- From: James Browning <notifications@github.com>
- Date: Wed, 03 Feb 2021 14:54:18 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/927/772882294@github.com>
> Node.js doesn’t currently expose its DOMException and throws errors that look like the DOM AbortError but are not actually DOMExceptions (same name and same code but without some of the quirks - quite painful since Node.is codes have a different format) > However since Node vendors certain bits of its core as user land modules (readable-stream) and exposing DOMException was a show stopper there we ended up with that compromise. If Node doesn't expose `DOMException` how can we vend abort errors for cases like the reject example above? Doing something hacky is possible like `try { abortSignal.assertNotAborted(); } catch (err) { reject(err); }` but this seems awkward. Just a thought I had, it could be possible to do it the other way around and have `.abort()` create an `AbortError` which is then attached to the abort event. This same exception would be thrown from `.assertNotAborted()` e.g.: ```js const controller = new AbortController(); controller.abort("user left the page"); const { signal } = controller; signal.addEventListener("abort", ({ abortError }) => { reject(abortError); // abortError has "user left the page" message doCleanup(); }); signal.assertNotAborted(); // throws the Abort Error with message "user left the page" ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/927#issuecomment-772882294
Received on Wednesday, 3 February 2021 22:55:09 UTC