@@ -2,6 +2,7 @@ import { addTracingExtensions, Hub, makeMain, Scope } from '@sentry/core';
2
2
import { NodeClient } from '@sentry/node' ;
3
3
import type { Transaction } from '@sentry/types' ;
4
4
import type { Handle } from '@sveltejs/kit' ;
5
+ import { redirect } from '@sveltejs/kit' ;
5
6
import { vi } from 'vitest' ;
6
7
7
8
import { sentryHandle , transformPageChunk } from '../../src/server/handle' ;
@@ -69,7 +70,21 @@ const enum Type {
69
70
Async = 'async' ,
70
71
}
71
72
72
- function resolve ( type : Type , isError : boolean ) : Parameters < Handle > [ 0 ] [ 'resolve' ] {
73
+ function resolve (
74
+ type : Type ,
75
+ isError : boolean ,
76
+ throwSpecialError ?: 'redirect' | 'httpError4xx' | 'httpError5xx' ,
77
+ ) : Parameters < Handle > [ 0 ] [ 'resolve' ] {
78
+ if ( throwSpecialError === 'redirect' ) {
79
+ throw redirect ( 302 , '/redirect' ) ;
80
+ }
81
+ if ( throwSpecialError === 'httpError4xx' ) {
82
+ throw { status : 404 , body : 'Not found' } ;
83
+ }
84
+ if ( throwSpecialError === 'httpError5xx' ) {
85
+ throw { status : 500 , body : 'Internal error' } ;
86
+ }
87
+
73
88
if ( type === Type . Sync ) {
74
89
return ( ..._args : unknown [ ] ) => {
75
90
if ( isError ) {
@@ -292,6 +307,22 @@ describe('handleSentry', () => {
292
307
}
293
308
} ) ;
294
309
310
+ it ( "doesn't send redirects in a request handler to Sentry" , async ( ) => {
311
+ try {
312
+ await sentryHandle ( ) ( { event : mockEvent ( ) , resolve : resolve ( type , false , 'redirect' ) } ) ;
313
+ } catch ( e ) {
314
+ expect ( mockCaptureException ) . toBeCalledTimes ( 0 ) ;
315
+ }
316
+ } ) ;
317
+
318
+ it ( "doesn't send Http 4xx errors in a request handler to Sentry" , async ( ) => {
319
+ try {
320
+ await sentryHandle ( ) ( { event : mockEvent ( ) , resolve : resolve ( type , false , 'httpError4xx' ) } ) ;
321
+ } catch ( e ) {
322
+ expect ( mockCaptureException ) . toBeCalledTimes ( 0 ) ;
323
+ }
324
+ } ) ;
325
+
295
326
it ( 'calls `transformPageChunk`' , async ( ) => {
296
327
const mockResolve = vi . fn ( ) . mockImplementation ( resolve ( type , isError ) ) ;
297
328
const event = mockEvent ( ) ;
0 commit comments