Mokkapps Logo

Vue Tip: Assign Handler for Uncaught Errors

Michael Hoffmann (Mokkapps) - Senior Frontend Developer (Freelancer)
December 15, 2021
1 Minuten Lesezeit
|
- Ansichten

You should monitor your errors in production. Vue therefore provides the errorHandler for uncaught errors during component render function and watchers. The handler gets called with the error and the application instance.

/**
* Handles Vue errors
* @param err - the error trace
* @param vm - VM component
* @param info - Vue-specific error info, e.g. which lifecycle hook the error was found in
*/
app.config.errorHandler = (err, vm, info) => {
  // handle error
}

Error tracking services Sentry and Bugsnag provide official integrations for the errorHandler.

It’s also possible to add the errorCaptured lifecycle hook to your component. It is called when an error from any descendent component is captured.



If you liked this tip, follow me on Twitter to get notified about new tips, blog posts and more content from me.

Alternatively (or additionally), you can also subscribe to my newsletter.

Sie haben einen Fehler in diesem Artikel gefunden? Sie möchten gerne etwas klarstellen, aktualisieren oder hinzufügen?

Alle meine Artikel können auf Github editiert werden. Jeder Fix ist willkommen, egal wie klein er sein mag!

Ändern auf Github