Last active
October 29, 2022 16:56
-
-
Save ApoTheOne/0fc7262df8df355c255847d982f33fdb to your computer and use it in GitHub Desktop.
Catch global error exception handle in client side front end javascript spa vue.js app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ref: https://stackoverflow.com/questions/52071212/how-to-implement-global-error-handling-in-vue | |
https://www.sitepoint.com/logging-errors-client-side-apps/ | |
In Main.ts | |
```typescript | |
window.onerror = function (msg, url, line, col, error) { | |
//code to handle or report error goes here | |
} | |
window.addEventListener('unhandledrejection', function(event) { | |
console.error('Unhandled rejection (promise: ', event.promise, ', reason: ', event.reason, ').'); | |
}); | |
// Vue.config.productionTip = false | |
// Vue.use(filters) | |
Vue.config.errorHandler = function (err, vm, info) { | |
// handle error | |
// `info` is a Vue-specific error info, e.g. which lifecycle hook | |
// the error was found in. Only available in 2.2.0+ | |
// Ref: https://vuejs.org/v2/api/#errorHandler | |
// Also check: https://vuejs.org/v2/api/#errorCaptured | |
} | |
new Vue({ | |
render: h => h(App), | |
router, | |
store, | |
// @ts-ignore | |
vuetify, | |
}).$mount('#app') | |
``` | |
Also worth checking: | |
https://www.loggly.com/blog/monitor-user-experience-using-client-side-json-logs/ | |
things to keep in mind by Sentry's CIO: | |
https://stackoverflow.com/questions/11257330/error-logging-for-javascript-on-client-side | |
https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions | |
CREATING OWN LOGGER: | |
https://www.sitepoint.com/logging-errors-client-side-apps/ | |
https://trinity.one/insights/web-analytics/client-side-javascript-error-logging-part-ii/ | |
LogLevel + plugins | |
stacktrace.js | |
refer pino |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment