Skip to content

Commit 1124961

Browse files
authored
fix(nextjs): Add env var to suppress API non-response meta-warning (#4706)
In the nextjs SDK, when we wrap users' API routes, we also wrap the response's `end` method, in order to keep the lambda running the route handler alive long enough to send events to Sentry. As a consequence, however, Next thinks a response hasn't been sent at all, because `end` hasn't been called within the timeframe that it expects, so it throws a warning in dev. A previous attempt[1] to fix this problem backfired[2], and had to be reverted[3], so as a compromise option for the moment, we log a warning about the Next warning, so at least people know it's nothing to worry about. Some people are finding this behavior spammy[4], though, so this PR adds an env variable check which allows a user to suppress our meta-warning, and also improves the warning itself so that people know the option is there. [1] #4139 [2] #4151 [3] #4516 [4] #3852 (comment)
1 parent ba14cc5 commit 1124961

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/nextjs/src/utils/withSentry.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
8686
try {
8787
const handlerResult = await origHandler(req, res);
8888

89-
if (process.env.NODE_ENV === 'development') {
89+
if (process.env.NODE_ENV === 'development' && !process.env.SENTRY_IGNORE_API_RESOLUTION_ERROR) {
9090
// eslint-disable-next-line no-console
9191
console.warn(
92-
'[sentry] If Next.js logs a warning "API resolved without sending a response", it\'s a false positive, which we\'re working to rectify.',
92+
`[sentry] If Next.js logs a warning "API resolved without sending a response", it's a false positive, which we're working to rectify.
93+
In the meantime, to suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
94+
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
9395
);
9496
}
9597

0 commit comments

Comments
 (0)