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