Skip to content

Commit 4c41fef

Browse files
authored
fix: Vue plugin doesnt explode if vm is undefined (#1111)
1 parent cf89f86 commit 4c41fef

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

Diff for: plugins/vue.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -22,20 +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-
componentName: formatComponentName(vm),
27-
propsData: vm.$options.propsData
28-
};
29-
30-
// lifecycleHook is not always available
31-
if (typeof info !== 'undefined') {
32-
metaData.lifecycleHook = info;
25+
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+
});
3339
}
3440

35-
Raven.captureException(error, {
36-
extra: metaData
37-
});
38-
3941
if (typeof _oldOnError === 'function') {
4042
_oldOnError.call(this, error, vm, info);
4143
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,14 @@ describe('Vue plugin', function() {
7575
lifecycleHook: 'mounted'
7676
});
7777
});
78+
79+
it('should not explode when `vm` is not defined', function() {
80+
vuePlugin(Raven, this.MockVue);
81+
assert.doesNotThrow(
82+
function() {
83+
this.MockVue.config.errorHandler(new Error('foo'));
84+
}.bind(this)
85+
);
86+
});
7887
});
7988
});

0 commit comments

Comments
 (0)