In Service Workers, is it possible to get a more meaningful error than "TypeError: Failed to fetch"?

35 Views Asked by At

Here's a minimal code of a service worker:

    if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
        event.respondWith(
            fetch(event.request).catch(function (error) {
                console.error(error);
            })
        );
        return;
    }

When there's a network issue, the error variable basically just says:

TypeError: Failed to fetch

We print this to the user in the "offline page", but it really never helps understanding what the problem is.

Is it possible to get something more meaningful?
Even if we could catch the Google Chrome code, like net::ERR_INTERNET_DISCONNECTED or net::ERR_CONNECTION_RESET, etc...

0

There are 0 best solutions below