From: Alexander Ebert Date: Thu, 28 Apr 2022 17:45:12 +0000 (+0200) Subject: Ignore connection errors caused by page navigation X-Git-Tag: 5.5.0_Alpha_5~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cd2ab79be458c1f5e85bf67fb9937e9ee88badfb;p=GitHub%2FWoltLab%2FWCF.git Ignore connection errors caused by page navigation See WoltLab/com.woltlab.wbb#539 --- diff --git a/ts/WoltLabSuite/Core/Ajax/DboAction.ts b/ts/WoltLabSuite/Core/Ajax/DboAction.ts index 241315f688..92b9f1266d 100644 --- a/ts/WoltLabSuite/Core/Ajax/DboAction.ts +++ b/ts/WoltLabSuite/Core/Ajax/DboAction.ts @@ -35,6 +35,8 @@ type RequestBody = { parameters?: Payload; }; +let ignoreConnectionErrors: boolean | undefined = undefined; + export class DboAction { private readonly actionName: string; private readonly className: string; @@ -49,6 +51,14 @@ export class DboAction { } static prepare(actionName: string, className: string): DboAction { + if (ignoreConnectionErrors === undefined) { + ignoreConnectionErrors = false; + + window.addEventListener("beforeunload", () => { + ignoreConnectionErrors = true; + }); + } + return new DboAction(actionName, className); } @@ -147,8 +157,10 @@ export class DboAction { if (error instanceof ApiError) { throw error; } else { - // Re-package the error for use in our global "unhandledrejection" handler. - throw new ConnectionError(error); + if (!ignoreConnectionErrors) { + // Re-package the error for use in our global "unhandledrejection" handler. + throw new ConnectionError(error); + } } } finally { if (showLoadingIndicator) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js index ffaa9bec14..664692bc7c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js @@ -14,6 +14,7 @@ define(["require", "exports", "tslib", "./Error", "./Status", "../Core"], functi exports.DboAction = void 0; AjaxStatus = tslib_1.__importStar(AjaxStatus); Core = tslib_1.__importStar(Core); + let ignoreConnectionErrors = undefined; class DboAction { constructor(actionName, className) { this._objectIDs = []; @@ -24,6 +25,12 @@ define(["require", "exports", "tslib", "./Error", "./Status", "../Core"], functi this.className = className; } static prepare(actionName, className) { + if (ignoreConnectionErrors === undefined) { + ignoreConnectionErrors = false; + window.addEventListener("beforeunload", () => { + ignoreConnectionErrors = true; + }); + } return new DboAction(actionName, className); } getAbortController() { @@ -105,8 +112,10 @@ define(["require", "exports", "tslib", "./Error", "./Status", "../Core"], functi throw error; } else { - // Re-package the error for use in our global "unhandledrejection" handler. - throw new Error_1.ConnectionError(error); + if (!ignoreConnectionErrors) { + // Re-package the error for use in our global "unhandledrejection" handler. + throw new Error_1.ConnectionError(error); + } } } finally {