Next.js Discord

Discord Forum

Error handling in route handler

Unanswered
Brewer's Sparrow posted this in #help-forum
Open in Discord
Brewer's SparrowOP
I am using an idp to build an authentication flow. I am getting logged in in two steps where the first step is that the user is redirected to a route handler on localhost:3000/login/entraId/callback . In that route handler I am then fetching the access token for the user. I would like to be able to also use the default error handling for nextJs, but I am having issues getting it to work in route handlers. I have tried NextResponse and redirects.
Is it possible to use the default error.tsx solution with route handlers or should I go about solving this with a server component and server actions instead?

1 Reply

Brewer's SparrowOP
I am using NextJS 15 with AppRouter