From 54e111886b51c563e4938c9f4fd346d8bd5c9bc7 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 28 Jun 2024 03:28:16 +0200 Subject: [PATCH 1/5] Improve logs (+add toasts) on save calls - Fixes #2429 --- public/script.js | 1 + public/scripts/bookmarks.js | 1 + .../quick-reply/src/QuickReplySet.js | 1 + public/scripts/group-chats.js | 21 ++++++++-- public/scripts/power-user.js | 41 +++++++++++-------- public/scripts/preset-manager.js | 10 +++-- 6 files changed, 49 insertions(+), 26 deletions(-) diff --git a/public/script.js b/public/script.js index 8b7b8d8f9..ec738648c 100644 --- a/public/script.js +++ b/public/script.js @@ -5775,6 +5775,7 @@ export async function saveChat(chat_name, withMetadata, mesId) { contentType: 'application/json', success: function (data) { }, error: function (jqXHR, exception) { + toastr.error('Check the server connection and reload the page to prevent data loss.', 'Chat could not be saved'); console.log(exception); console.log(jqXHR); }, diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index f6a2d1d70..14ba977f8 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -336,6 +336,7 @@ async function convertSoloToGroupChat() { if (!createChatResponse.ok) { console.error('Group chat creation unsuccessful'); + toastr.error('Group chat creation unsuccessful'); return; } diff --git a/public/scripts/extensions/quick-reply/src/QuickReplySet.js b/public/scripts/extensions/quick-reply/src/QuickReplySet.js index 106084081..7004c75c6 100644 --- a/public/scripts/extensions/quick-reply/src/QuickReplySet.js +++ b/public/scripts/extensions/quick-reply/src/QuickReplySet.js @@ -231,6 +231,7 @@ export class QuickReplySet { this.rerender(); } else { warn(`Failed to save Quick Reply Set: ${this.name}`); + console.error('QR could not be saved', response); } } diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index fdc91c1df..5e61c207b 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -492,7 +492,13 @@ async function saveGroupChat(groupId, shouldSaveGroup) { body: JSON.stringify({ id: chat_id, chat: [...chat] }), }); - if (shouldSaveGroup && response.ok) { + if (!response.ok) { + toastr.error('Check the server connection and reload the page to prevent data loss.', 'Group Chat could not be saved'); + console.error('Group chat could not be saved', response); + return; + } + + if (shouldSaveGroup) { await editGroup(groupId, false, false); } } @@ -546,9 +552,11 @@ export async function renameGroupMember(oldAvatar, newAvatar, newName) { body: JSON.stringify({ id: chatId, chat: [...messages] }), }); - if (saveChatResponse.ok) { - console.log(`Renamed character ${newName} in group chat: ${chatId}`); + if (!saveChatResponse.ok) { + throw new Error('Group member could not be renamed'); } + + console.log(`Renamed character ${newName} in group chat: ${chatId}`); } } } @@ -1828,11 +1836,16 @@ export async function saveGroupBookmarkChat(groupId, name, metadata, mesId) { await editGroup(groupId, true, false); - await fetch('/api/chats/group/save', { + const response = await fetch('/api/chats/group/save', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ id: name, chat: [...trimmed_chat] }), }); + + if (!response.ok) { + toastr.error('Check the server connection and reload the page to prevent data loss.', 'Group chat could not be saved'); + console.error('Group chat could not be saved', response); + } } function onSendTextareaInput() { diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index e167109e8..a9d2414c0 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -2316,26 +2316,30 @@ async function saveTheme(name = undefined, theme = undefined) { body: JSON.stringify(theme), }); - if (response.ok) { - const themeIndex = themes.findIndex(x => x.name == name); - - if (themeIndex == -1) { - themes.push(theme); - const option = document.createElement('option'); - option.selected = true; - option.value = name; - option.innerText = name; - $('#themes').append(option); - } - else { - themes[themeIndex] = theme; - $(`#themes option[value="${name}"]`).attr('selected', true); - } - - power_user.theme = name; - saveSettingsDebounced(); + if (!response.ok) { + toastr.error('Check the server connection and reload the page to prevent data loss.', 'Theme could not be saved'); + console.error('Theme could not be saved', response); + return; } + const themeIndex = themes.findIndex(x => x.name == name); + + if (themeIndex == -1) { + themes.push(theme); + const option = document.createElement('option'); + option.selected = true; + option.value = name; + option.innerText = name; + $('#themes').append(option); + } + else { + themes[themeIndex] = theme; + $(`#themes option[value="${name}"]`).attr('selected', true); + } + + power_user.theme = name; + saveSettingsDebounced(); + return theme; } @@ -2439,6 +2443,7 @@ async function saveMovingUI() { saveSettingsDebounced(); } else { toastr.warning('failed to save MovingUI state.'); + console.error('MovingUI could not be saved', response); } } diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 9043e8a91..953f67ca9 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -182,17 +182,19 @@ class PresetManager { async savePreset(name, settings) { const preset = settings ?? this.getPresetSettings(name); - const res = await fetch('/api/presets/save', { + const response = await fetch('/api/presets/save', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ preset, name, apiId: this.apiId }), }); - if (!res.ok) { - toastr.error('Failed to save preset'); + if (!response.ok) { + toastr.error('Check the server connection and reload the page to prevent data loss.', 'Preset could not be saved'); + console.error('Preset could not be saved', response); + return; } - const data = await res.json(); + const data = await response.json(); name = data.name; this.updateList(name, preset); From 043eead149d75f056879329aa3c4009669dbccd5 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:06:33 +0000 Subject: [PATCH 2/5] Don't show empty toasts in slash command executor --- public/scripts/slash-commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 9c79ab46d..8284b17f8 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -3296,7 +3296,7 @@ export async function executeSlashCommandsOnChatInput(text, options = {}) { result = new SlashCommandClosureResult(); result.isError = true; result.errorMessage = e.message; - if (e.cause !== 'abort') { + if (e.cause !== 'abort' && e.message) { toastr.error(e.message); } } finally { From 985c2dd0318d0ce4f6bedb6d495e903103692b94 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:09:22 +0000 Subject: [PATCH 3/5] Don't indicate success in saving presets --- public/scripts/preset-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 953f67ca9..28e4089d2 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -191,7 +191,7 @@ class PresetManager { if (!response.ok) { toastr.error('Check the server connection and reload the page to prevent data loss.', 'Preset could not be saved'); console.error('Preset could not be saved', response); - return; + throw new Error('Preset could not be saved'); } const data = await response.json(); From 2293828f8ef6d7ca41aa3138838b1a79e353d944 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:14:38 +0000 Subject: [PATCH 4/5] Ditto, for chat completion --- public/scripts/openai.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 440a37f04..9d3d13029 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -3365,6 +3365,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { } } else { toastr.error('Failed to save preset'); + throw new Error('Failed to save preset'); } } From 190bed8025f02cd9dccf4610a56505cebd1ed0e7 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:01:28 +0000 Subject: [PATCH 5/5] Fix theme and movingUI toasts --- public/scripts/power-user.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index a9d2414c0..8751e2d2e 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -2319,7 +2319,7 @@ async function saveTheme(name = undefined, theme = undefined) { if (!response.ok) { toastr.error('Check the server connection and reload the page to prevent data loss.', 'Theme could not be saved'); console.error('Theme could not be saved', response); - return; + throw new Error('Theme could not be saved'); } const themeIndex = themes.findIndex(x => x.name == name); @@ -2405,12 +2405,14 @@ function getNewTheme(parsed) { } async function saveMovingUI() { - const name = await callGenericPopup('Enter a name for the MovingUI Preset:', POPUP_TYPE.INPUT); + const popupResult = await callGenericPopup('Enter a name for the MovingUI Preset:', POPUP_TYPE.INPUT); - if (!name) { + if (!popupResult) { return; } + const name = String(popupResult); + const movingUIPreset = { name, movingUIState: power_user.movingUIState, @@ -2442,7 +2444,7 @@ async function saveMovingUI() { power_user.movingUIPreset = name; saveSettingsDebounced(); } else { - toastr.warning('failed to save MovingUI state.'); + toastr.error('Failed to save MovingUI state.'); console.error('MovingUI could not be saved', response); } }