@@ -14,12 +14,14 @@ import {
1414 logger ,
1515} from '@sentry/utils' ;
1616
17+ import { getFutureFlagsServer } from './futureFlags' ;
1718import type {
1819 AppData ,
1920 CreateRequestHandlerFunction ,
2021 DataFunction ,
2122 DataFunctionArgs ,
2223 EntryContext ,
24+ FutureConfig ,
2325 HandleDocumentRequestFunction ,
2426 ReactRouterDomPkg ,
2527 RemixRequest ,
@@ -31,6 +33,8 @@ import type {
3133import { extractData , getRequestMatch , isDeferredData , isResponse , json , matchServerRoutes } from './vendor/response' ;
3234import { normalizeRemixRequest } from './web-fetch' ;
3335
36+ let FUTURE_FLAGS : FutureConfig | undefined ;
37+
3438// Flag to track if the core request handler is instrumented.
3539export let isRequestHandlerWrapped = false ;
3640
@@ -57,7 +61,16 @@ async function extractResponseError(response: Response): Promise<unknown> {
5761 return responseData ;
5862}
5963
60- async function captureRemixServerException ( err : unknown , name : string , request : Request ) : Promise < void > {
64+ /**
65+ * Captures an exception happened in the Remix server.
66+ *
67+ * @param err The error to capture.
68+ * @param name The name of the origin function.
69+ * @param request The request object.
70+ *
71+ * @returns A promise that resolves when the exception is captured.
72+ */
73+ export async function captureRemixServerException ( err : unknown , name : string , request : Request ) : Promise < void > {
6174 // Skip capturing if the thrown error is not a 5xx response
6275 // https://remix.run/docs/en/v1/api/conventions#throwing-responses-in-loaders
6376 if ( isResponse ( err ) && err . status < 500 ) {
@@ -146,7 +159,10 @@ function makeWrappedDocumentRequestFunction(
146159
147160 span ?. finish ( ) ;
148161 } catch ( err ) {
149- await captureRemixServerException ( err , 'documentRequest' , request ) ;
162+ if ( ! FUTURE_FLAGS ?. v2_errorBoundary ) {
163+ await captureRemixServerException ( err , 'documentRequest' , request ) ;
164+ }
165+
150166 throw err ;
151167 }
152168
@@ -183,7 +199,10 @@ function makeWrappedDataFunction(origFn: DataFunction, id: string, name: 'action
183199 currentScope . setSpan ( activeTransaction ) ;
184200 span ?. finish ( ) ;
185201 } catch ( err ) {
186- await captureRemixServerException ( err , name , args . request ) ;
202+ if ( ! FUTURE_FLAGS ?. v2_errorBoundary ) {
203+ await captureRemixServerException ( err , name , args . request ) ;
204+ }
205+
187206 throw err ;
188207 }
189208
@@ -430,6 +449,7 @@ function makeWrappedCreateRequestHandler(
430449 isRequestHandlerWrapped = true ;
431450
432451 return function ( this : unknown , build : ServerBuild , ...args : unknown [ ] ) : RequestHandler {
452+ FUTURE_FLAGS = getFutureFlagsServer ( build ) ;
433453 const newBuild = instrumentBuild ( build ) ;
434454 const requestHandler = origCreateRequestHandler . call ( this , newBuild , ...args ) ;
435455
0 commit comments