From 5c92243cc2464bd31a666d5a3e81c34fe734ad20 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 14 May 2022 16:32:17 +0200 Subject: [PATCH] Suppress error messages when aborting `fetch()` See https://www.woltlab.com/community/thread/295566-fetch-is-aborted-bei-suchergebnissen/ --- ts/WoltLabSuite/Core/Ajax/DboAction.ts | 7 +++++++ .../install/files/js/WoltLabSuite/Core/Ajax/DboAction.js | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ts/WoltLabSuite/Core/Ajax/DboAction.ts b/ts/WoltLabSuite/Core/Ajax/DboAction.ts index 92b9f1266d..33cc993078 100644 --- a/ts/WoltLabSuite/Core/Ajax/DboAction.ts +++ b/ts/WoltLabSuite/Core/Ajax/DboAction.ts @@ -157,6 +157,13 @@ export class DboAction { if (error instanceof ApiError) { throw error; } else { + if (error instanceof DOMException && error.name === "AbortError") { + // `fetch()` will reject the promise with an `AbortError` when + // the request is either explicitly (through an `AbortController`) + // or implicitly (page navigation) aborted. + return; + } + if (!ignoreConnectionErrors) { // Re-package the error for use in our global "unhandledrejection" handler. throw new ConnectionError(error); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js index 664692bc7c..adb1a29011 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js @@ -112,6 +112,12 @@ define(["require", "exports", "tslib", "./Error", "./Status", "../Core"], functi throw error; } else { + if (error instanceof DOMException && error.name === "AbortError") { + // `fetch()` will reject the promise with an `AbortError` when + // the request is either explicitly (through an `AbortController`) + // or implicitly (page navigation) aborted. + return; + } if (!ignoreConnectionErrors) { // Re-package the error for use in our global "unhandledrejection" handler. throw new Error_1.ConnectionError(error); -- 2.20.1