Next.js Discord

Discord Forum

No error messages on api routes

Unanswered
teo.villanueva posted this in #help-forum
Open in Discord
Hello! As the title says, I have a route like the following

// GET /api/test
export function GET() {
  throw new Error("My error");
}


and the error does not get logged to the console. This example is quite simple but i'm having issues debugging complex code where unexpected error may occur.

I'm using sentry and these are my versions

"@sentry/nextjs": "10.5.0",
"next": "15.4.7",

5 Replies

Next.js suppresses unhandled errors in route handlers
you need to replace throw new errror with
Sentry.captureException(new Error('Oh no.'));
then import * as Sentry from '@sentry/nextjs';
at the top