I am using fetch to make requests to the backend of my application, which uses an OAuth authentication provider.
When the session expires, the fetch request is redirected to the authentication provider, causing it to fail because of a CORS error (which I cannot change).
In this case, fetch throws a TypeError: failed to fetch.
Unfortunately, I am also getting a TypeError: failed to fetch, when the network is down or the request times out for another reason.
How can I reliably discriminate between these failure modes?
I have not found any useful properties on the thrown TypeError, that would allow these failures to be distinguished.
It is possible to catch redirects using the redirect: "manual" option.
fetch(url, {redirect: "manual"})
While it is not possible to catch the redirection URL for security purposes, this is an acceptable resolution for me at this point.