File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 1
1
import type { Client } from '@sentry/types' ;
2
2
3
3
import { defaultStackParser } from '../../src' ;
4
- import { eventFromPlainObject } from '../../src/eventbuilder' ;
4
+ import { eventFromPlainObject , exceptionFromError } from '../../src/eventbuilder' ;
5
5
6
6
jest . mock ( '@sentry/core' , ( ) => {
7
7
const original = jest . requireActual ( '@sentry/core' ) ;
@@ -62,3 +62,25 @@ describe('eventFromPlainObject', () => {
62
62
} ) ;
63
63
} ) ;
64
64
} ) ;
65
+
66
+ describe ( 'exceptionFromError ' , ( ) => {
67
+ it ( 'correctly reads error type and value from built-in `Error` subclass' , ( ) => {
68
+ const exceptionJSON = exceptionFromError ( ( ) => [ ] , new TypeError ( "Expected type 'ChewToy', got type 'Shoe'" ) ) ;
69
+
70
+ expect ( exceptionJSON ) . toEqual ( {
71
+ type : 'TypeError' ,
72
+ value : "Expected type 'ChewToy', got type 'Shoe'" ,
73
+ } ) ;
74
+ } ) ;
75
+
76
+ it ( 'correctly reads error type and value from user-defined `Error` subclass' , ( ) => {
77
+ class DidNotFetch extends Error { }
78
+
79
+ const exceptionJSON = exceptionFromError ( ( ) => [ ] , new DidNotFetch ( "Failed to fetch requested object: 'ball'" ) ) ;
80
+
81
+ expect ( exceptionJSON ) . toEqual ( {
82
+ type : 'DidNotFetch' ,
83
+ value : "Failed to fetch requested object: 'ball'" ,
84
+ } ) ;
85
+ } ) ;
86
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import type { Client } from '@sentry/types' ;
2
2
3
3
import { defaultStackParser , Scope } from '../src' ;
4
- import { eventFromUnknownInput } from '../src/eventbuilder' ;
4
+ import { eventFromUnknownInput , exceptionFromError } from '../src/eventbuilder' ;
5
5
6
6
const testScope = new Scope ( ) ;
7
7
@@ -74,3 +74,25 @@ describe('eventFromUnknownInput', () => {
74
74
} ) ;
75
75
} ) ;
76
76
} ) ;
77
+
78
+ describe ( 'exceptionFromError ' , ( ) => {
79
+ it ( 'correctly reads error type and value from built-in `Error` subclass' , ( ) => {
80
+ const exceptionJSON = exceptionFromError ( ( ) => [ ] , new TypeError ( "Expected type 'ChewToy', got type 'Shoe'" ) ) ;
81
+
82
+ expect ( exceptionJSON ) . toEqual ( {
83
+ type : 'TypeError' ,
84
+ value : "Expected type 'ChewToy', got type 'Shoe'" ,
85
+ } ) ;
86
+ } ) ;
87
+
88
+ it ( 'correctly reads error type and value from user-defined `Error` subclass' , ( ) => {
89
+ class DidNotFetch extends Error { }
90
+
91
+ const exceptionJSON = exceptionFromError ( ( ) => [ ] , new DidNotFetch ( "Failed to fetch requested object: 'ball'" ) ) ;
92
+
93
+ expect ( exceptionJSON ) . toEqual ( {
94
+ type : 'DidNotFetch' ,
95
+ value : "Failed to fetch requested object: 'ball'" ,
96
+ } ) ;
97
+ } ) ;
98
+ } ) ;
You can’t perform that action at this time.
0 commit comments