Handle aborting status check gracefully

7952b5f2c9a255d0f18a145a653a425d2e3ab13d

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +20 -5Ignore whitespace
public/script.js+11 -5
@@ -242,6 +242,7 @@ import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'
242242import { initDynamicStyles } from './scripts/dynamic-styles.js';
243243import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js';
244244import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
245+import { AbortReason } from './scripts/util/AbortReason.js';
245246
246247//exporting functions and vars for mods
247248export {
@@ -978,8 +979,8 @@ async function fixViewport() {
978979 document.body.style.position = '';
979980}
980981
981982function cancelStatusCheck(reason = 'Manually cancelled status check') {
982983 abortStatusCheck?.abort(new AbortReason(reason));
983984 abortStatusCheck = new AbortController();
984985 setOnlineStatus('no_connection');
985986}
@@ -1229,7 +1230,12 @@ async function getStatusTextgen() {
12291230 toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
12301231 }
12311232 } catch (err) {
1232- console.error('Error getting status', err);
1233+ if (err instanceof AbortReason) {
1234+ console.info('Status check aborted.', err.reason);
1235+ } else {
1236+ console.error('Error getting status', err);
1237+
1238+ }
12331239 setOnlineStatus('no_connection');
12341240 }
12351241
@@ -9317,7 +9323,7 @@ jQuery(async function () {
93179323 $('#groupCurrentMemberListToggle .inline-drawer-icon').trigger('click');
93189324 }, 200);
93199325
93209326 $(document).on('click', '.api_loading', () => cancelStatusCheck('Canceled because connecting was manually canceled'));
93219327
93229328 //////////INPUT BAR FOCUS-KEEPING LOGIC/////////////
93239329 let S_TAPreviouslyFocused = false;
@@ -10076,7 +10082,7 @@ jQuery(async function () {
1007610082 });
1007710083
1007810084 $('#main_api').change(function () {
10079- cancelStatusCheck();
10085+ cancelStatusCheck("Canceled because main api changed");
1008010086 changeMainAPI();
1008110087 saveSettingsDebounced();
1008210088 });
public/scripts/util/AbortReason.js+9 -0
@@ -0,0 +1,9 @@
1+export class AbortReason {
2+ constructor(reason) {
3+ this.reason = reason;
4+ }
5+
6+ toString() {
7+ return this.reason;
8+ }
9+}