From cd2ab79be458c1f5e85bf67fb9937e9ee88badfb Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 28 Apr 2022 19:45:12 +0200 Subject: [PATCH] Ignore connection errors caused by page navigation See WoltLab/com.woltlab.wbb#539 --- ts/WoltLabSuite/Core/Ajax/DboAction.ts | 16 ++++++++++++++-- .../files/js/WoltLabSuite/Core/Ajax/DboAction.js | 13 +++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) 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 { -- 2.20.1