- From: origin <notifications@github.com>
- Date: Fri, 14 Mar 2025 05:17:58 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1815@github.com>
origin721 created an issue (whatwg/fetch#1815) ### What is the issue with the Fetch Standard? Proposal: Add a Mechanism to Suppress Console Errors for Expected Fetch Failures Currently, there is no standardized way to prevent certain expected errors (such as AbortError) from being logged to the console as UnhandledPromiseRejection. Issue When using fetch in the following way: js Copy Edit const promise = fetch(url, { signal }).then(response => response.json()); promise.catch(error => { // Handle the error, but it still logs to the console }); If the request is aborted, an AbortError will always be printed to the console as an unhandled rejection even though it is explicitly handled in .catch(). Even if we attempt to catch and rethrow the error, there is no built-in way to indicate that the error should not be reported in the console: js fetch(url, { signal }) .then(response => response.json()) .catch(error => { if (error.name === "AbortError") { error.suppressConsoleError = true; // This does nothing, but should exist } return Promise.reject(error); }); Proposed Solution Introduce a mechanism (such as error.suppressConsoleError = true) to indicate that a specific error should not be reported as UnhandledPromiseRejection in the browser console. Alternatively, a fetch option like { suppressAbortError: true } could be added to prevent AbortError logging when an aborted request is expected behavior. This would improve developer control over error handling without requiring workarounds like catching the error at a higher level or creating unresolved promises that may lead to memory leaks. Would it be possible to consider adding such an option to the fetch API? 🚀 -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1815 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1815@github.com>
Received on Friday, 14 March 2025 12:18:02 UTC