-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recovering from fetch failures #939
Comments
event.respondWith(
something.then(response => {
if (!event.isResponseAcceptable(response)) throw Error("Boom");
return response;
}).catch(() => {
return fetch(event.request).catch(() => genericErrorPage);
})
) |
An alternative proposed by @wanderview is some kind of self.addEventListener('fetcherror', event => {
event.fallbackToDefaultRequest();
}); The benefits of this is the isolation of your error handling code from the thing that might be causing the error. However, you can only fallback to default behaviour, not provide some other kind of response. But do we need a whole new event? What if the request's body has already been used? Is that a problem? |
I should point out that the method names I've used above are somewhat deliberately ridiculous, we can bikeshed later. |
The reason I like the |
Why would that not throw just the same? |
If we do something like |
Throw where? One idea is to make
Agreed. If it doesn't need additional data from the |
I was chatting with @esprehn and he mentioned an idea around a service worker event that fires if a tab shows an error page, allowing you to get information on the error, and navigate the client if you want. His use-case was recovering from full tab crashes, but it feels similar to what we're talking about here. |
Sounds interesting and useful, but is there potential evil here with https cert error pages, etc? |
(please ignore my previous and now deleted comment, that's what I get for commenting without reading the full issue for context) Imo adding an event for browser crashes would be amazing! If something like this got implemented I can promise that we'd be using it within a few days. The use case for browser crashes is different enough from an https cert error that imo it'd be fine if there was a whitelist for which events that this happens for. It'd probably be good for there to be a whitelist anyway and some standard for error names/types or something like that. |
F2F:
|
This should happen for "network failure" errors that result in a generic error page being shown. |
If your SW is buggy, or something changes in a particular browser that causes it to start throwing errors, the user gets nothing until you fix your SW (unless the browser provides a "retry without service worker" feature).
It'd be nice to allow the developer to recover in these cases
In many cases, a
.catch()
at the end of therespondWith
promise lets them do that, but not in the case of a response that fetch deems unacceptable, eg an opaque response to a CORS request.The text was updated successfully, but these errors were encountered: