Handle aborting status check gracefully
| @@ -242,6 +242,7 @@ import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js' | ||
| 242 | 242 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; |
| 243 | 243 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; |
| 244 | 244 | import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 245 | +import { AbortReason } from './scripts/util/AbortReason.js'; | |
| 245 | 246 | |
| 246 | 247 | //exporting functions and vars for mods |
| 247 | 248 | export { |
| @@ -978,8 +979,8 @@ async function fixViewport() { | ||
| 978 | 979 | document.body.style.position = ''; |
| 979 | 980 | } |
| 980 | 981 | |
| 981 | 982 | function cancelStatusCheck(reason = 'Manually cancelled status check') { |
| 982 | 983 | abortStatusCheck?.abort(new AbortReason(reason)); |
| 983 | 984 | abortStatusCheck = new AbortController(); |
| 984 | 985 | setOnlineStatus('no_connection'); |
| 985 | 986 | } |
| @@ -1229,7 +1230,12 @@ async function getStatusTextgen() { | ||
| 1229 | 1230 | toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true }); |
| 1230 | 1231 | } |
| 1231 | 1232 | } catch (err) { |
| 1233 | + if (err instanceof AbortReason) { | |
| 1234 | + console.info('Status check aborted.', err.reason); | |
| 1235 | + } else { | |
| 1232 | 1236 | console.error('Error getting status', err); |
| 1237 | + | |
| 1238 | + } | |
| 1233 | 1239 | setOnlineStatus('no_connection'); |
| 1234 | 1240 | } |
| 1235 | 1241 | |
| @@ -9317,7 +9323,7 @@ jQuery(async function () { | ||
| 9317 | 9323 | $('#groupCurrentMemberListToggle .inline-drawer-icon').trigger('click'); |
| 9318 | 9324 | }, 200); |
| 9319 | 9325 | |
| 9320 | 9326 | $(document).on('click', '.api_loading', () => cancelStatusCheck('Canceled because connecting was manually canceled')); |
| 9321 | 9327 | |
| 9322 | 9328 | //////////INPUT BAR FOCUS-KEEPING LOGIC///////////// |
| 9323 | 9329 | let S_TAPreviouslyFocused = false; |
| @@ -10076,7 +10082,7 @@ jQuery(async function () { | ||
| 10076 | 10082 | }); |
| 10077 | 10083 | |
| 10078 | 10084 | $('#main_api').change(function () { |
| 10079 | - cancelStatusCheck(); | |
| 10085 | + cancelStatusCheck("Canceled because main api changed"); | |
| 10080 | 10086 | changeMainAPI(); |
| 10081 | 10087 | saveSettingsDebounced(); |
| 10082 | 10088 | }); |
| @@ -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 | +} | |