I am creating a webapp and trying to capture all the errors thrown anywhere in the vue.js webapp.
I was looking at errorHandler but it only captures error during render or watchers, as stated:
Assign a handler for uncaught errors during component render and watchers. The handler gets called with the error and the Vue instance.
Getting cue from this question, I wrote following code:
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
console.log('Inside window.onerror')
console.log(errorMsg, ' ', url, ' ', lineNumber, ' ', column, ' ', errorObj)
return false
}
window.addEventListener('error', function (e) {
console.log('Inside error Listener', e.message)
})
Above both gets called but I don't any details of the errors with these. in all the cases I get errorMessage
as script error
What can be better way to get details of all the errors and send it to some centralised place like sentry.
For error handling, we can assign a handler function to Vue. config. errorHandler . The handler gets called for any uncaught exceptions within any Vue instance (Vue components) throughout the application.
Double-click on the line number in your VSCode to add a breakpoint. Then, run npm run serve to serve your project. Go to the debug view in your editor and select your preferred browser configuration. Press 5 or click the green play button.
Right-click anywhere in the webpage and then select Inspect. Or, press F12 . DevTools opens next to the webpage. In the top right of DevTools, the Open Console to view errors button displays an error about the webpage.
Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue.
You mentioned Sentry in your answer, and if your goal is getting errors logged there, all you need to add is Raven.js, and the Vue plugin.
Sentry has documentation on doing this here: https://docs.sentry.io/clients/javascript/integrations/vue/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With