Improve logs (+add toasts) on save calls

- Fixes #2429
This commit is contained in:
Wolfsblvt
2024-06-28 03:28:16 +02:00
parent b8295ac8f5
commit 54e111886b
6 changed files with 49 additions and 26 deletions

View File

@ -5775,6 +5775,7 @@ export async function saveChat(chat_name, withMetadata, mesId) {
contentType: 'application/json', contentType: 'application/json',
success: function (data) { }, success: function (data) { },
error: function (jqXHR, exception) { 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(exception);
console.log(jqXHR); console.log(jqXHR);
}, },

View File

@ -336,6 +336,7 @@ async function convertSoloToGroupChat() {
if (!createChatResponse.ok) { if (!createChatResponse.ok) {
console.error('Group chat creation unsuccessful'); console.error('Group chat creation unsuccessful');
toastr.error('Group chat creation unsuccessful');
return; return;
} }

View File

@ -231,6 +231,7 @@ export class QuickReplySet {
this.rerender(); this.rerender();
} else { } else {
warn(`Failed to save Quick Reply Set: ${this.name}`); warn(`Failed to save Quick Reply Set: ${this.name}`);
console.error('QR could not be saved', response);
} }
} }

View File

@ -492,7 +492,13 @@ async function saveGroupChat(groupId, shouldSaveGroup) {
body: JSON.stringify({ id: chat_id, chat: [...chat] }), 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); await editGroup(groupId, false, false);
} }
} }
@ -546,9 +552,11 @@ export async function renameGroupMember(oldAvatar, newAvatar, newName) {
body: JSON.stringify({ id: chatId, chat: [...messages] }), body: JSON.stringify({ id: chatId, chat: [...messages] }),
}); });
if (saveChatResponse.ok) { if (!saveChatResponse.ok) {
console.log(`Renamed character ${newName} in group chat: ${chatId}`); 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 editGroup(groupId, true, false);
await fetch('/api/chats/group/save', { const response = await fetch('/api/chats/group/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: name, chat: [...trimmed_chat] }), 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() { function onSendTextareaInput() {

View File

@ -2316,7 +2316,12 @@ async function saveTheme(name = undefined, theme = undefined) {
body: JSON.stringify(theme), body: JSON.stringify(theme),
}); });
if (response.ok) { 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); const themeIndex = themes.findIndex(x => x.name == name);
if (themeIndex == -1) { if (themeIndex == -1) {
@ -2334,7 +2339,6 @@ async function saveTheme(name = undefined, theme = undefined) {
power_user.theme = name; power_user.theme = name;
saveSettingsDebounced(); saveSettingsDebounced();
}
return theme; return theme;
} }
@ -2439,6 +2443,7 @@ async function saveMovingUI() {
saveSettingsDebounced(); saveSettingsDebounced();
} else { } else {
toastr.warning('failed to save MovingUI state.'); toastr.warning('failed to save MovingUI state.');
console.error('MovingUI could not be saved', response);
} }
} }

View File

@ -182,17 +182,19 @@ class PresetManager {
async savePreset(name, settings) { async savePreset(name, settings) {
const preset = settings ?? this.getPresetSettings(name); const preset = settings ?? this.getPresetSettings(name);
const res = await fetch('/api/presets/save', { const response = await fetch('/api/presets/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ preset, name, apiId: this.apiId }), body: JSON.stringify({ preset, name, apiId: this.apiId }),
}); });
if (!res.ok) { if (!response.ok) {
toastr.error('Failed to save preset'); 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; name = data.name;
this.updateList(name, preset); this.updateList(name, preset);