diff --git a/public/script.js b/public/script.js index 214a27c34..1b2537aac 100644 --- a/public/script.js +++ b/public/script.js @@ -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) { - console.error('Error getting status', 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(); }); diff --git a/public/scripts/util/AbortReason.js b/public/scripts/util/AbortReason.js new file mode 100644 index 000000000..3218fdb87 --- /dev/null +++ b/public/scripts/util/AbortReason.js @@ -0,0 +1,9 @@ +export class AbortReason { + constructor(reason) { + this.reason = reason; + } + + toString() { + return this.reason; + } +}