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',
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);
},

View File

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

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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);