9

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.

tony19
  • 125,647
  • 18
  • 229
  • 307
Saurabh
  • 71,488
  • 40
  • 181
  • 244
  • Have you seen log4javascript? This may cover your needs – AldoRomo88 Feb 17 '17 at 17:23
  • Have the same issue. But I don't get anything in console. I found this answer on stackoverflow, it's about future but how nows, may be it'll help. [unhandledrejection event listener](https://stackoverflow.com/questions/31472439/catch-all-unhandled-javascript-promise-rejections) – Crashh Oct 04 '17 at 13:24
  • You may be getting `script error` because those errors occur in scripts loaded from a different origin and details of them are not reported to prevent leaking of information. You may try to configure the CORS policy for those scripts. See more details from https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror. – d.i.joe Sep 28 '20 at 13:13

1 Answers1

1

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/

cdignam
  • 1,376
  • 1
  • 15
  • 21