setCatchHandler.mjs 748 B

12345678910111213141516171819202122232425
  1. /*
  2. Copyright 2019 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.mjs';
  8. import './_version.mjs';
  9. /**
  10. * If a Route throws an error while handling a request, this `handler`
  11. * will be called and given a chance to provide a response.
  12. *
  13. * @param {workbox.routing.Route~handlerCallback} handler A callback
  14. * function that returns a Promise resulting in a Response.
  15. *
  16. * @alias workbox.routing.setCatchHandler
  17. */
  18. export const setCatchHandler = (handler) => {
  19. const defaultRouter = getOrCreateDefaultRouter();
  20. defaultRouter.setCatchHandler(handler);
  21. };