Skip to content

Commit 0815309

Browse files
authored
fix(nextjs): Await flush in api handlers (#14023)
1 parent f358790 commit 0815309

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
8686
return target.apply(thisArg, argArray);
8787
},
8888
});
89-
9089
try {
9190
return await wrappingTarget.apply(thisArg, args);
9291
} catch (e) {
@@ -110,7 +109,9 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
110109
setHttpStatus(span, 500);
111110
span.end();
112111

113-
vercelWaitUntil(flushSafelyWithTimeout());
112+
// we need to await the flush here to ensure that the error is captured
113+
// as the runtime freezes as soon as the error is thrown below
114+
await flushSafelyWithTimeout();
114115

115116
// We rethrow here so that nextjs can do with the error whatever it would normally do. (Sometimes "whatever it
116117
// would normally do" is to allow the error to bubble up to the global handlers - another reason we need to mark

0 commit comments

Comments
 (0)