Skip to content

Instantly share code, notes, and snippets.

@trainiac
Last active May 31, 2017 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trainiac/c78cbee38de1738e0b2e2e184f6e356d to your computer and use it in GitHub Desktop.
Save trainiac/c78cbee38de1738e0b2e2e184f6e356d to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import { some } from 'utils/arr'
const harmlessMessages = [
// Facebook throws error that doesn't matter to us
'https://staticxx.facebook.com',
// Chrome from autocomplete bug.
'__gCrWeb.autofill.extractForms',
]
const isHarmlessMessage = message => {
if (!message) {
return false
}
return some(harmless => message.indexOf(harmless) !== -1, harmlessMessages)
}
export default onError => {
window.addEventListener('error', e => {
let info = {
type: 'ClientError',
title: 'Something Not Awesome Happened',
message: "Yeah...that's about all I can tell you",
details: ['Oh yeah and I like hamburgers'],
}
if (e.error) {
const message = e.error.message
if (isHarmlessMessage(message)) {
return
}
info = {
...info,
title: 'Unhandled Error',
message,
details: [e.error.stack],
}
}
onError(info, e)
})
window.addEventListener('unhandledrejection', e => {
const info = {
type: 'UnhandledRejection',
title: 'Unhandled Promise Rejection',
message: 'A promise was rejected without a reason',
details: ['Try searching for reject()'],
}
if (e.reason) {
info.message = e.reason.message
info.details = [e.reason.stack]
}
onError(info, e)
})
Vue.config.errorHandler = function vueErrorHandler (error, component, info) {
const vueErrorInfo = {
type: 'VueError',
title: 'Vue Error Handler',
message: error.message,
details: [
`Component name: ${component.$options.name}`,
`Vue Info: ${info}`,
error.stack,
],
}
onError(vueErrorInfo, error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment