Skip to content

Commit 4987084

Browse files
committed
fix: Send raw error when vm is undefined in Vue plugin
1 parent 4c41fef commit 4987084

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

Diff for: plugins/vue.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ function vuePlugin(Raven, Vue) {
2222

2323
var _oldOnError = Vue.config.errorHandler;
2424
Vue.config.errorHandler = function VueErrorHandler(error, vm, info) {
25+
var metaData = {};
26+
27+
// vm and lifecycleHook are not always available
2528
if (Object.prototype.toString.call(vm) === '[object Object]') {
26-
var metaData = {
27-
componentName: formatComponentName(vm),
28-
propsData: vm.$options.propsData
29-
};
30-
31-
// lifecycleHook is not always available
32-
if (typeof info !== 'undefined') {
33-
metaData.lifecycleHook = info;
34-
}
35-
36-
Raven.captureException(error, {
37-
extra: metaData
38-
});
29+
metaData.componentName = formatComponentName(vm);
30+
metaData.propsData = vm.$options.propsData;
31+
}
32+
33+
if (arguments.length === 3 && typeof info !== 'undefined') {
34+
metaData.lifecycleHook = info;
3935
}
4036

37+
Raven.captureException(error, {
38+
extra: metaData
39+
});
40+
4141
if (typeof _oldOnError === 'function') {
4242
_oldOnError.call(this, error, vm, info);
4343
}

Diff for: test/plugins/vue.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,11 @@ describe('Vue plugin', function() {
8484
}.bind(this)
8585
);
8686
});
87+
88+
it('should still send a raw error when `vm` is not defined', function() {
89+
vuePlugin(Raven, this.MockVue);
90+
this.MockVue.config.errorHandler(new Error('foo'));
91+
assert.isTrue(Raven.captureException.calledOnce);
92+
});
8793
});
8894
});

0 commit comments

Comments
 (0)