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 BlueSky to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter :
Vue Tip: Use Teleport to Render a Component in a Different Place
Vue Tip: Simple Expressions in Templates