Custom error page with NextJS Route handlers
Answered
Eulophid wasp posted this in #help-forum
Eulophid waspOP
Hey guys, anyone knows how to render a custom error page if a call to an api errors (e.g. the api returns 403 status code)? Right now, the error page will just be the default browser error page.
Answered by joulev
You need to redirect to a page. There is no way to return a full react page from a route handler easily. Route handlers are for returning machine-readable responses (json, binary) not human-readable responses such as a whole html page.
3 Replies
Lionhead
@Eulophid wasp Hi!
i think this could help https://nextjs.org/docs/pages/building-your-application/routing/custom-error
i think this could help https://nextjs.org/docs/pages/building-your-application/routing/custom-error
@Eulophid wasp Hey guys, anyone knows how to render a custom error page if a call to an api errors (e.g. the api returns 403 status code)? Right now, the error page will just be the default browser error page.
You need to redirect to a page. There is no way to return a full react page from a route handler easily. Route handlers are for returning machine-readable responses (json, binary) not human-readable responses such as a whole html page.
Answer
Eulophid waspOP
@joulev gotcha, thanks!