Merge pull request #2430 from SillyTavern/toast-save-errors

Improve logs (+add toasts) on save calls
This commit is contained in:
Cohee 2024-06-28 12:03:42 +03:00 committed by GitHub
commit 46830a27d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 56 additions and 30 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

@ -3365,6 +3365,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
} }
} else { } else {
toastr.error('Failed to save preset'); toastr.error('Failed to save preset');
throw new Error('Failed to save preset');
} }
} }

View File

@ -2316,26 +2316,30 @@ async function saveTheme(name = undefined, theme = undefined) {
body: JSON.stringify(theme), body: JSON.stringify(theme),
}); });
if (response.ok) { if (!response.ok) {
const themeIndex = themes.findIndex(x => x.name == name); 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);
if (themeIndex == -1) { throw new Error('Theme could not be saved');
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();
} }
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; return theme;
} }
@ -2401,12 +2405,14 @@ function getNewTheme(parsed) {
} }
async function saveMovingUI() { 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; return;
} }
const name = String(popupResult);
const movingUIPreset = { const movingUIPreset = {
name, name,
movingUIState: power_user.movingUIState, movingUIState: power_user.movingUIState,
@ -2438,7 +2444,8 @@ async function saveMovingUI() {
power_user.movingUIPreset = name; power_user.movingUIPreset = name;
saveSettingsDebounced(); saveSettingsDebounced();
} else { } else {
toastr.warning('failed to save MovingUI state.'); toastr.error('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);
throw new Error('Preset could not be saved');
} }
const data = await res.json(); const data = await response.json();
name = data.name; name = data.name;
this.updateList(name, preset); this.updateList(name, preset);

View File

@ -3296,7 +3296,7 @@ export async function executeSlashCommandsOnChatInput(text, options = {}) {
result = new SlashCommandClosureResult(); result = new SlashCommandClosureResult();
result.isError = true; result.isError = true;
result.errorMessage = e.message; result.errorMessage = e.message;
if (e.cause !== 'abort') { if (e.cause !== 'abort' && e.message) {
toastr.error(e.message); toastr.error(e.message);
} }
} finally { } finally {