47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import {RavenStatic} from 'raven-js';
|
|
import Vue from 'vue';
|
|
|
|
/*tslint:disable:no-unsafe-any no-any*///hack
|
|
function formatComponentName(vm: any): string {
|
|
if(vm === undefined) return 'undefined';
|
|
if(vm.$root === vm) return '<root instance>';
|
|
const name = vm._isVue
|
|
? vm.$options.name || vm.$options._componentTag
|
|
: vm.name;
|
|
return (name ? `component <${name}>` : 'anonymous component') + (vm._isVue && vm.$options.__file ? ` at ${vm.$options.__file}` : '');
|
|
}
|
|
//tslint:enable
|
|
|
|
/*tslint:disable:no-unbound-method strict-type-predicates*///hack
|
|
export default function VueRaven(this: void, raven: RavenStatic): RavenStatic {
|
|
if(typeof Vue.config !== 'object') return raven;
|
|
const oldOnError = Vue.config.errorHandler;
|
|
Vue.config.errorHandler = (error: Error, vm: Vue, info: string): void => {
|
|
raven.captureException(error, {
|
|
extra: {
|
|
componentName: formatComponentName(vm),
|
|
//propsData: vm.$options.propsData,
|
|
info
|
|
}
|
|
});
|
|
|
|
if(typeof oldOnError === 'function') oldOnError.call(this, error, vm);
|
|
else console.log(error);
|
|
};
|
|
|
|
const oldOnWarn = Vue.config.warnHandler;
|
|
Vue.config.warnHandler = (message: string, vm: Vue, trace: string): void => {
|
|
raven.captureMessage(message + trace, {
|
|
extra: {
|
|
componentName: formatComponentName(vm)
|
|
//propsData: vm.$options.propsData
|
|
}
|
|
});
|
|
console.warn(`${message}: ${trace}`);
|
|
if(typeof oldOnWarn === 'function')
|
|
oldOnWarn.call(this, message, vm, trace);
|
|
};
|
|
|
|
return raven;
|
|
}
|
|
//tslint:enable
|