Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 9ef8272

Browse files
committed
New post 🚀
1 parent d443053 commit 9ef8272

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

_drafts/2020-08-10-webpack-workbox-service-worker-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ registerCacheFirstRouteUsing('image', CACHE_IMAGES_NAME, imagesExpirationPlugin)
150150
//...other code...
151151
```
152152

153-
...set catch handler...
153+
Now there's a question we didn't answer: how do we manage the requests that will fail? There are multiple possibilities to manage these cases. In our case I decided to go for a global catch handler. By calling `setCatchHandler` it is possible to catch all the network/cache error for all the routes defined. We can give a callback to this function where we can define an error recovery strategy for each type of error. In our case we respond with the offline page (see the offline cache defined in the precache/install event) if the error happens on a resource of type `document` (so an html page that can be loaded completely), and we return a generic error for all the other fail (images loading fail, scripts fail etc.). Below you can find the implementation of the cache handler.
154154

155155
```typescript
156156
import { setCatchHandler } from 'workbox-routing';

0 commit comments

Comments
 (0)