Handle aborting status check gracefully

This commit is contained in:
Wolfsblvt 2024-09-07 23:27:46 +02:00
parent d99dfb9168
commit 7952b5f2c9
2 changed files with 20 additions and 5 deletions

View File

@ -242,6 +242,7 @@ import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'
import { initDynamicStyles } from './scripts/dynamic-styles.js';
import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js';
import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
import { AbortReason } from './scripts/util/AbortReason.js';
//exporting functions and vars for mods
export {
@ -978,8 +979,8 @@ async function fixViewport() {
document.body.style.position = '';
}
function cancelStatusCheck() {
abortStatusCheck?.abort();
function cancelStatusCheck(reason = 'Manually cancelled status check') {
abortStatusCheck?.abort(new AbortReason(reason));
abortStatusCheck = new AbortController();
setOnlineStatus('no_connection');
}
@ -1229,7 +1230,12 @@ async function getStatusTextgen() {
toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
}
} catch (err) {
if (err instanceof AbortReason) {
console.info('Status check aborted.', err.reason);
} else {
console.error('Error getting status', err);
}
setOnlineStatus('no_connection');
}
@ -9317,7 +9323,7 @@ jQuery(async function () {
$('#groupCurrentMemberListToggle .inline-drawer-icon').trigger('click');
}, 200);
$(document).on('click', '.api_loading', cancelStatusCheck);
$(document).on('click', '.api_loading', () => cancelStatusCheck('Canceled because connecting was manually canceled'));
//////////INPUT BAR FOCUS-KEEPING LOGIC/////////////
let S_TAPreviouslyFocused = false;
@ -10076,7 +10082,7 @@ jQuery(async function () {
});
$('#main_api').change(function () {
cancelStatusCheck();
cancelStatusCheck("Canceled because main api changed");
changeMainAPI();
saveSettingsDebounced();
});

View File

@ -0,0 +1,9 @@
export class AbortReason {
constructor(reason) {
this.reason = reason;
}
toString() {
return this.reason;
}
}