@@ -18,6 +18,12 @@ interface RequestHandlerWrapperOptions {
18
18
options : CloudflareOptions ;
19
19
request : Request < unknown , IncomingRequestCfProperties < unknown > > ;
20
20
context : ExecutionContext ;
21
+ /**
22
+ * If true, errors will be captured, rethrown and sent to Sentry.
23
+ * Otherwise, errors are rethrown but not captured.
24
+ * @default true
25
+ */
26
+ captureErrors ?: boolean ;
21
27
}
22
28
23
29
/**
@@ -28,7 +34,7 @@ export function wrapRequestHandler(
28
34
handler : ( ...args : unknown [ ] ) => Response | Promise < Response > ,
29
35
) : Promise < Response > {
30
36
return withIsolationScope ( async isolationScope => {
31
- const { options, request } = wrapperOptions ;
37
+ const { options, request, captureErrors = true } = wrapperOptions ;
32
38
33
39
// In certain situations, the passed context can become undefined.
34
40
// For example, for Astro while prerendering pages at build time.
@@ -67,7 +73,9 @@ export function wrapRequestHandler(
67
73
try {
68
74
return await handler ( ) ;
69
75
} catch ( e ) {
70
- captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
76
+ if ( captureErrors ) {
77
+ captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
78
+ }
71
79
throw e ;
72
80
} finally {
73
81
waitUntil ?.( flush ( 2000 ) ) ;
@@ -91,7 +99,9 @@ export function wrapRequestHandler(
91
99
setHttpStatus ( span , res . status ) ;
92
100
return res ;
93
101
} catch ( e ) {
94
- captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
102
+ if ( captureErrors ) {
103
+ captureException ( e , { mechanism : { handled : false , type : 'cloudflare' } } ) ;
104
+ }
95
105
throw e ;
96
106
} finally {
97
107
waitUntil ?.( flush ( 2000 ) ) ;
0 commit comments