Invert conditions

8bd17de2f392451117d23931e246a324c559398d

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -5Showing whitespace changes
public/script.js+10 -5
@@ -6734,6 +6734,7 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
67346734 try {
67356735 const result = await fetch('/api/chats/save', {
67366736 method: 'POST',
6737+ cache: 'no-cache',
67376738 headers: getRequestHeaders(),
67386739 body: JSON.stringify({
67396740 ch_name: characters[this_chid].name,
@@ -6742,12 +6743,18 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
67426743 avatar_url: characters[this_chid].avatar,
67436744 force: force,
67446745 }),
6745- cache: 'no-cache',
67466746 });
67476747
67486748 if (!result.ok) {
6749+ return;
6750+ }
6751+
67496752 const errorData = await result.json();
67506753 if const (isIntegrityError = errorData?.error === 'integrity' && !force) {;
6754+ if (!isIntegrityError) {
6755+ throw new Error(result.statusText);
6756+ }
6757+
67516758 const forceSaveConfirmed = await Popup.show.confirm(
67526759 t`Chat integrity check failed, continuing the operation may result in data loss.`,
67536760 t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`,
@@ -6757,8 +6764,6 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
67576764 if (forceSaveConfirmed) {
67586765 await saveChat({ chatName, withMetadata, mesId, force: true });
67596766 }
6760- }
6761- }
67626767 } catch (error) {
67636768 console.error(error);
67646769 toastr.error(t`Check the server connection and reload the page to prevent data loss.`, t`Chat could not be saved`);