Add handlerDidError plugin callback #2569
Labels
Discuss
An open question, where input from the community would be appreciated.
Feature Request
workbox-strategies
Milestone
Library Affected:
workbox-strategies
Issue or Feature Request Description:
workbox-routing
currently provides "fallback" support via thesetCatchHandler()
method, which is usually written as a bigswitch
statement with a bunch of different response strategies for different types of requests all bunched together.In addition to this approach, which is implemented on the global-router level, it would be a good developer experience to expose
Strategy
-level fallback support, with a handler that gets triggered whenever the "main" handler for aStrategy
results in aWorkboxError
.This new
setCatchHandler
method on theStrategy
base class would also be associated with a new TypeScript callback signature, that matched the normalhandlerCallback
signature, but included an additionalerror
property, in case the developer wants access to the underlying error. (Theworkbox-routing
setCatchHandler()
should also use this new callback signature, and pass the underlying error through there as well.)You can approximate this now by creating your own
handlerCallback
with atry
/catch
block and a call to aStrategy
inside of it, but that's more awkward than it needs to be. Code that's currently:Could be rewritten as:
I think it should be pretty clean to support this with the new
Strategy
base class that @philipwalton put in place for v6.The text was updated successfully, but these errors were encountered: