Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ApoTheOne/0fc7262df8df355c255847d982f33fdb to your computer and use it in GitHub Desktop.
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
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