Javascript is required
Mokkapps LogoMichael Hoffmann

Vue Tip: Assign Handler for Uncaught Errors

Michael Hoffmann (Mokkapps) - Senior Frontend Developer (Freelancer)
Michael Hoffmann
Dec 15, 2021
1 min read
|
117 views
Script
Vue Tip: Assign Handler for Uncaught Errors Image

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 Vue tip, follow me on Twitter to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue newsletter.