@@ -35,18 +35,39 @@ describe('handleError', () => {
35
35
// ...
36
36
} as RequestEvent ;
37
37
38
+ // @ts -expect-error - leaving this input as is for SvelteKit 1.x compatibility (status and message are missing)
38
39
const returnVal = await wrappedHandleError ( { error : mockError , event : mockEvent } ) ;
39
40
40
41
expect ( returnVal ) . not . toBeDefined ( ) ;
41
42
expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 0 ) ;
42
43
expect ( consoleErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
43
44
} ) ;
44
45
46
+ it ( 'doesn\'t capture "Not found" errors for incorrect navigations' , async ( ) => {
47
+ const wrappedHandleError = handleErrorWithSentry ( ) ;
48
+
49
+ const returnVal = await wrappedHandleError ( {
50
+ error : new Error ( '404 /asdf/123' ) ,
51
+ event : requestEvent ,
52
+ status : 404 ,
53
+ message : 'Not Found' ,
54
+ } ) ;
55
+
56
+ expect ( returnVal ) . not . toBeDefined ( ) ;
57
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 0 ) ;
58
+ expect ( consoleErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
59
+ } ) ;
60
+
45
61
describe ( 'calls captureException' , ( ) => {
46
62
it ( 'invokes the default handler if no handleError func is provided' , async ( ) => {
47
63
const wrappedHandleError = handleErrorWithSentry ( ) ;
48
64
const mockError = new Error ( 'test' ) ;
49
- const returnVal = await wrappedHandleError ( { error : mockError , event : requestEvent } ) ;
65
+ const returnVal = await wrappedHandleError ( {
66
+ error : mockError ,
67
+ event : requestEvent ,
68
+ status : 500 ,
69
+ message : 'Internal Error' ,
70
+ } ) ;
50
71
51
72
expect ( returnVal ) . not . toBeDefined ( ) ;
52
73
expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -58,7 +79,12 @@ describe('handleError', () => {
58
79
it ( 'invokes the user-provided error handler' , async ( ) => {
59
80
const wrappedHandleError = handleErrorWithSentry ( handleError ) ;
60
81
const mockError = new Error ( 'test' ) ;
61
- const returnVal = ( await wrappedHandleError ( { error : mockError , event : requestEvent } ) ) as any ;
82
+ const returnVal = ( await wrappedHandleError ( {
83
+ error : mockError ,
84
+ event : requestEvent ,
85
+ status : 500 ,
86
+ message : 'Internal Error' ,
87
+ } ) ) as any ;
62
88
63
89
expect ( returnVal . message ) . toEqual ( 'Whoops!' ) ;
64
90
expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments