Skip to content

Commit

Permalink
feat(service-worker): Add to ErrorHandler that the error is from SW
Browse files Browse the repository at this point in the history
With Angular v11.0.4 and commit [_fix(service-worker): handle error with
ErrorHandler_](552419d)
Angular start to send all service worker registration errors to the Angular
standard `ErrorHandler.handleError()` interface, instead of logging them in the
console.

But service worker registration errors are a lot different than other code
errors:
- They are frequent, for example, they happen a lot with Chrome v84,
  Chrome v85, Firefox 84, and Samsung Internet v13.
- Most applications can run even without a registered service worker.

Use case example:
- All errors send to `ErrorHandler.handleError()` show a `window.confirm`
  pop-up, so developers see the error right away during development, and users
  of the application have a huge error message before trying to use a broken
  application.
- All errors from service worker registration are ignored, so users are not
  annoyed in that case.

With the actual code, inside `ErrorHandler.handleError()`, we can't
differentiate a service worker registration error from any other error, and
service worker registration errors are already not clear at all, so we are
losing a valuable piece of information.
I propose to add a "source" of the error, like that service worker registration
errors are cachable inside `ErrorHandler.handleError()`.
  • Loading branch information
H--o-l committed Dec 22, 2020
1 parent 5ba7bcd commit 055b27e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/service-worker/src/module.ts
Expand Up @@ -130,7 +130,7 @@ export function ngswAppInitializer(
() => readyToRegister$.pipe(take(1)).subscribe(
() => navigator.serviceWorker.register(script, {scope: options.scope}).catch(err => {
const errorHandler = injector.get(ErrorHandler);
errorHandler.handleError(err);
errorHandler.handleError({source: 'Service worker registration', error: err});
})));
};
return initializer;
Expand Down

0 comments on commit 055b27e

Please sign in to comment.