Skip to content

Commit e546506

Browse files
committed
also flush before rethrowing error
1 parent 7b1c5a2 commit e546506

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/nextjs/src/utils/withSentry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
100100
captureException(objectifiedErr);
101101
}
102102

103+
// Make sure we have a chance to finish the transaction and flush events to Sentry before the handler errors
104+
// out. (Apps which are deployed on Vercel run their API routes in lambdas, and those lambdas will shut down the
105+
// moment they detect an error, so it's important to get this done before rethrowing the error. Apps not
106+
// deployed serverlessly will run into this cleanup function again in `res.end(), but it'll just no-op.)
107+
await finishSentryProcessing(res);
108+
103109
// We rethrow here so that nextjs can do with the error whatever it would normally do. (Sometimes "whatever it
104110
// would normally do" is to allow the error to bubble up to the global handlers - another reason we need to mark
105111
// the error as already having been captured.)

0 commit comments

Comments
 (0)