Re: [whatwg/fetch] More informative error types (#526)

I came across this issue today and had to come up with a best-effort approach. I tweeted about it:

> I can't find a reliable way to detect retryable connection/network errors using fetch across @nodejs, @bunjavascript, @googlechrome and other platform. It's really unfortunate that the spec authors landed on throwing TypeError for pretty much anything that can go wrong. This includes CORS and CSP violations on the browser which are not retryable and those errors are opaque to JS code. DOMException is already used by AbortSignal and could have been a good choice since it's `.name` property reflects an error code. An explicit FetchError would have been even better still.
> [Playground link](https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&noUnusedLocals=true&noUnusedParameters=true&target=9&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true#code/IYZwngdgxgBAZgV2gFwJYHsIwCbtcgCgEoYBvAKBipmQCcwzLrngB3YfeAU2SgAsCAIj7JkABxAAuAPTSuAD2ABbMQBsuAOijolggDREmVAL4wowXnxgEutWiQrNmqONdQgAwpghcoaTACidui0NnZEDkZOzNoQIOjqGra0IUK0PPTAAEbqZt6+-ljJITDoUFAIdlzYgobRJlHMyHwprDDJANxRxuQ95IgoGFjuXhA+fkNBKaHJkjBIANYQ6KwQkVQu1skwALw7MBAIqqrr1OnIlVhwwKogXF0NTLIwXgButiDcljCoWAAiXGWMFAMFYXGOTFiIGQPxAACFWndaFNdlFtr9ocBoFx0K4ACpgMRcKYlABkpLRdg0Si4IBAwAA5ppkOgADIrWweUBcYgaTG0ZAgADq+AEgmuqHU2Bo6C+-FqXUhmGhsIAcuhsMS7KjmOi4sgsVAcfjCVrpjByZTaNTafSmRoWeywbQuXdefzBSLmkI4Dx+PAOFKFeQlfrYXCkCidlFkKbce1tXt9oJ0FkAFYFQQW0kwQQQZRcLO-BO0bMljT5mm7Pa50bjQok2iCRVUKEw9wAcUBtlQUCjMbjrm2SdzqYzfizluYgm0mqLRW1U+osaJ8eSWg1XGryehtF+DMnFN1VNnzLZHJd3OI29zvm86TuyGbIao50u4cRthRAB9v2rNz+f6dt2e59tqv7hpGdhdH0uD4LyzSAgQ147AAfHkcQJJoqjoAyQgQL2hYROQQA)

![image](https://github.com/whatwg/fetch/assets/678548/9b34a3e5-671f-4c8b-9a4f-eeccabd7431d)

Unfortunately I cannot distinguish CSP/CORS-related errors from actual network errors using this code but it’s as close as I can get. 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/526#issuecomment-1800839717
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/526/1800839717@github.com>

Received on Wednesday, 8 November 2023 01:07:18 UTC