Suppress error messages when aborting `fetch()`
authorAlexander Ebert <ebert@woltlab.com>
Sat, 14 May 2022 14:32:17 +0000 (16:32 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 14 May 2022 14:32:17 +0000 (16:32 +0200)
See https://www.woltlab.com/community/thread/295566-fetch-is-aborted-bei-suchergebnissen/

ts/WoltLabSuite/Core/Ajax/DboAction.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/DboAction.js

index 92b9f1266d67f7fe5db36080fa849653194999c0..33cc99307870182976fc18d331eb2c04146715d4 100644 (file)
@@ -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);
index 664692bc7ccf4728cdc3c18a5f5538568886337e..adb1a290116aebd109be0eab7e99655a000b23f4 100644 (file)
@@ -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);