Last active
May 31, 2017 20:35
-
-
Save trainiac/c78cbee38de1738e0b2e2e184f6e356d to your computer and use it in GitHub Desktop.
This file contains 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
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