Skip to content
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

New Route.setCatchHandler() method #2318

Closed
jeffposnick opened this issue Jan 7, 2020 · 1 comment · Fixed by #2699
Closed

New Route.setCatchHandler() method #2318

jeffposnick opened this issue Jan 7, 2020 · 1 comment · Fixed by #2699
Assignees
Labels
Feature Request Good First Issue This would be an ideal issue for a new contributor to take on. workbox-routing

Comments

@jeffposnick
Copy link
Contributor

Library Affected:
workbox-routing

I was thinking that we should add in a Route-level setCatchHandler() method, which would behave like the existing Router.setCatchHandler(), but instead of being a global to the Router instance, it would apply only when there's an exception throw by the HandlerCallback associated with the specific Route.

Something like:

const navigationRoute = new NavigationRoute(new NetworkOnly());

// Everything that extends Route would support setCatchHandler():
navigationRoute.setCatchHandler((routeHandlerCallbackParams) => {
  return caches.match('/offline.html');
  // Or do something using routeHandlerCallbackParams to create a Response
});

registerRoute(navigationRoute);

This would be post-v5, as it should be backwards-compatible.

@jeffposnick jeffposnick added the Good First Issue This would be an ideal issue for a new contributor to take on. label Dec 10, 2020
@Snugug Snugug self-assigned this Dec 11, 2020
@Snugug
Copy link
Contributor

Snugug commented Dec 11, 2020

Run route's catch handler, fall back to global if route's CH throws (if one exists)

Snugug added a commit to Snugug/workbox that referenced this issue Dec 11, 2020
jeffposnick added a commit that referenced this issue Jan 5, 2021
* Add setCatchHandler option for routes

Resolves #2318

* Check for catchHandler in Router catch

* Update packages/workbox-routing/src/Router.ts

Co-authored-by: Jeffrey Posnick <jeffy@google.com>

Co-authored-by: Jeffrey Posnick <jeffy@google.com>
mdndeveloper added a commit to mdndeveloper/chrome-workbox that referenced this issue Dec 3, 2022
* Add setCatchHandler option for routes

Resolves GoogleChrome/workbox#2318

* Check for catchHandler in Router catch

* Update packages/workbox-routing/src/Router.ts

Co-authored-by: Jeffrey Posnick <jeffy@google.com>

Co-authored-by: Jeffrey Posnick <jeffy@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Good First Issue This would be an ideal issue for a new contributor to take on. workbox-routing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants