File tree Expand file tree Collapse file tree 2 files changed +41
-16
lines changed Expand file tree Collapse file tree 2 files changed +41
-16
lines changed Original file line number Diff line number Diff line change @@ -22,16 +22,23 @@ function vuePlugin(Raven, Vue) {
2222 if ( ! Vue || ! Vue . config ) return ;
2323
2424 var _oldOnError = Vue . config . errorHandler ;
25- Vue . config . errorHandler = function VueErrorHandler ( error , vm ) {
25+ Vue . config . errorHandler = function VueErrorHandler ( error , vm , info ) {
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+
2636 Raven . captureException ( error , {
27- extra : {
28- componentName : formatComponentName ( vm ) ,
29- propsData : vm . $options . propsData
30- }
37+ extra : metaData
3138 } ) ;
3239
3340 if ( typeof _oldOnError === 'function' ) {
34- _oldOnError . call ( this , error , vm ) ;
41+ _oldOnError . call ( this , error , vm , info ) ;
3542 }
3643 } ;
3744}
Original file line number Diff line number Diff line change @@ -19,17 +19,13 @@ describe('Vue plugin', function() {
1919 it ( 'should capture component name and propsData' , function ( ) {
2020 vuePlugin ( Raven , this . MockVue ) ;
2121
22- this . MockVue . config . errorHandler (
23- new Error ( 'foo' ) ,
24- {
25- $options : {
26- propsData : {
27- foo : 'bar'
28- }
22+ this . MockVue . config . errorHandler ( new Error ( 'foo' ) , {
23+ $options : {
24+ propsData : {
25+ foo : 'bar'
2926 }
30- } ,
31- { } /* vm */
32- ) ;
27+ }
28+ } ) ;
3329
3430 assert . isTrue ( Raven . captureException . calledOnce ) ;
3531
@@ -57,5 +53,27 @@ describe('Vue plugin', function() {
5753 assert . equal ( errorHandler . args [ 0 ] [ 0 ] , err ) ;
5854 assert . equal ( errorHandler . args [ 0 ] [ 1 ] , vm ) ;
5955 } ) ;
56+
57+ it ( 'should capture lifecycle hook' , function ( ) {
58+ vuePlugin ( Raven , this . MockVue ) ;
59+
60+ this . MockVue . config . errorHandler (
61+ new Error ( 'foo' ) ,
62+ {
63+ $options : {
64+ propsData : { }
65+ }
66+ } ,
67+ 'mounted'
68+ ) ;
69+
70+ assert . isTrue ( Raven . captureException . calledOnce ) ;
71+
72+ assert . deepEqual ( Raven . captureException . args [ 0 ] [ 1 ] . extra , {
73+ propsData : { } ,
74+ componentName : 'anonymous component' ,
75+ lifecycleHook : 'mounted'
76+ } ) ;
77+ } ) ;
6078 } ) ;
6179} ) ;
You can’t perform that action at this time.
0 commit comments