Skip to content

fix: Send raw error when vm is undefined in Vue plugin #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions plugins/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ function vuePlugin(Raven, Vue) {

var _oldOnError = Vue.config.errorHandler;
Vue.config.errorHandler = function VueErrorHandler(error, vm, info) {
var metaData = {};

// vm and lifecycleHook are not always available
if (Object.prototype.toString.call(vm) === '[object Object]') {
var metaData = {
componentName: formatComponentName(vm),
propsData: vm.$options.propsData
};

// lifecycleHook is not always available
if (typeof info !== 'undefined') {
metaData.lifecycleHook = info;
}

Raven.captureException(error, {
extra: metaData
});
metaData.componentName = formatComponentName(vm);
metaData.propsData = vm.$options.propsData;
}

if (typeof info !== 'undefined') {
metaData.lifecycleHook = info;
}

Raven.captureException(error, {
extra: metaData
});

if (typeof _oldOnError === 'function') {
_oldOnError.call(this, error, vm, info);
}
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/vue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ describe('Vue plugin', function() {
}.bind(this)
);
});

it('should still send a raw error when `vm` is not defined', function() {
vuePlugin(Raven, this.MockVue);
this.MockVue.config.errorHandler(new Error('foo'));
assert.isTrue(Raven.captureException.calledOnce);
});
});
});