Skip to content

Commit ec6822d

Browse files
committed
manually set error status on response
1 parent 68aa490 commit ec6822d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/nextjs/src/utils/withSentry.ts

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
150150
captureException(objectifiedErr);
151151
}
152152

153+
// Because we're going to finish and send the transaction before passing the error onto nextjs, it won't yet
154+
// have had a chance to set the status to 500, so unless we do it ourselves now, we'll incorrectly report that
155+
// the transaction was error-free
156+
res.statusCode = 500;
157+
res.statusMessage = 'Internal Server Error';
158+
153159
// Make sure we have a chance to finish the transaction and flush events to Sentry before the handler errors
154160
// out. (Apps which are deployed on Vercel run their API routes in lambdas, and those lambdas will shut down the
155161
// moment they detect an error, so it's important to get this done before rethrowing the error. Apps not

0 commit comments

Comments
 (0)