File tree 1 file changed +10
-5
lines changed
packages/nextjs/src/utils
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -91,8 +91,8 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
91
91
} ) ;
92
92
captureException ( e ) ;
93
93
}
94
- throw e ;
95
94
( res as AugmentedNextApiResponse ) . __sentryCapturedError = e ;
95
+ res . end ( ) ;
96
96
}
97
97
} ) ;
98
98
@@ -121,16 +121,21 @@ function wrapEndMethod(origEnd: ResponseEndMethod): WrappedResponseEndMethod {
121
121
await transactionFinished ;
122
122
}
123
123
124
- // flush the event queue to ensure that events get sent to Sentry before the response is finished and the lambda
125
- // ends
124
+ // Flush the event queue to ensure that events get sent to Sentry before the response is finished and the lambda
125
+ // ends. If there was an error, rethrow it so that the normal exception-handling mechanisms can apply.
126
126
try {
127
127
logger . log ( 'Flushing events...' ) ;
128
128
await flush ( 2000 ) ;
129
129
logger . log ( 'Done flushing events' ) ;
130
130
} catch ( e ) {
131
131
logger . log ( `Error while flushing events:\n${ e } ` ) ;
132
+ } finally {
133
+ if ( capturedError ) {
134
+ console . log ( 'about to rethrow error' ) ;
135
+ throw capturedError ;
136
+ }
137
+ console . log ( 'about to call origEnd' ) ;
138
+ return origEnd . call ( this , ...args ) ;
132
139
}
133
-
134
- return origEnd . call ( this , ...args ) ;
135
140
} ;
136
141
}
You can’t perform that action at this time.
0 commit comments