Skip to content

Commit c6bdbfd

Browse files
authored
fix(nextjs): Log false positive warning only if request is unfinished. (#6070)
We have been logging a warning to point out that Next.JS's warning is a false positive, but it seems not necessary anymore unless the user prefers disabling auto-wrapping and uses `withSentry` wrapper manually. This PR updates the warning message and ensures it's only logged when the request is not yet finished, before the result is returned.
1 parent 8d7e050 commit c6bdbfd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/nextjs/src/config/wrappers/withSentryAPI.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,17 @@ export function withSentry(origHandler: NextApiHandler, parameterizedRoute?: str
134134
try {
135135
const handlerResult = await origHandler(req, res);
136136

137-
if (process.env.NODE_ENV === 'development' && !process.env.SENTRY_IGNORE_API_RESOLUTION_ERROR) {
137+
if (
138+
process.env.NODE_ENV === 'development' &&
139+
!process.env.SENTRY_IGNORE_API_RESOLUTION_ERROR &&
140+
!res.finished
141+
// This can only happen (not always) when the user is using `withSentry` manually, which we're deprecating.
142+
// Warning suppression on Next.JS is only necessary in that case.
143+
) {
138144
// eslint-disable-next-line no-console
139145
console.warn(
140-
`[sentry] If Next.js logs a warning "API resolved without sending a response", it's a false positive, which we're working to rectify.
141-
In the meantime, to suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
146+
`[sentry] If Next.js logs a warning "API resolved without sending a response", it's a false positive, which may happen when you use \`withSentry\` manually to wrap your routes.
147+
To suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
142148
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
143149
);
144150
}

0 commit comments

Comments
 (0)