Skip to content

fix(nextjs): Await flush in api handlers #14023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/nextjs/src/common/wrapApiHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
return target.apply(thisArg, argArray);
},
});

try {
return await wrappingTarget.apply(thisArg, args);
} catch (e) {
Expand All @@ -110,7 +109,9 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
setHttpStatus(span, 500);
span.end();

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

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