Skip to content

Commit 2e6eae2

Browse files
committed
manually set error status on response
1 parent e546506 commit 2e6eae2

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+
// Because we're going to finish and send the transaction before passing the error onto nextjs, it won't yet
104+
// have had a chance to set the status to 500, so unless we do it ourselves now, we'll incorrectly report that
105+
// the transaction was error-free
106+
res.statusCode = 500;
107+
res.statusMessage = 'Internal Server Error';
108+
103109
// Make sure we have a chance to finish the transaction and flush events to Sentry before the handler errors
104110
// out. (Apps which are deployed on Vercel run their API routes in lambdas, and those lambdas will shut down the
105111
// moment they detect an error, so it's important to get this done before rethrowing the error. Apps not

0 commit comments

Comments
 (0)