Returning 500 or 503 Error Response Status Code from Layout or Page #52378
Replies: 7 comments
-
I'm also interested in having this feature. Created this discussion a while ago #50383 |
Beta Was this translation helpful? Give feedback.
-
Is there a way to achieve this with Page Router? I have seen that |
Beta Was this translation helpful? Give feedback.
-
I'm also curious as well. Would love a function like |
Beta Was this translation helpful? Give feedback.
-
We are humans, we need this |
Beta Was this translation helpful? Give feedback.
-
👋 Any progress now? I also need to return a 500 page to the user when the API returns an error |
Beta Was this translation helpful? Give feedback.
-
We need this |
Beta Was this translation helpful? Give feedback.
-
Any update on that ? |
Beta Was this translation helpful? Give feedback.
-
The
error.js
functionality is great for customizing the visual display when errors occur at different levels of the app:https://nextjs.org/docs/app/building-your-application/routing/error-handling
However, as far as I'm aware, it always returns a 200 response code. This might be ok for small contained errors, but for substantial errors, I would like to return an error status code to the client from a
layout.js
orpage.js
.For example, if I am retrieving data from an API in
page.js
and the API returns an error or is unavailable, then I cannot render my page, so I would like to return a 500 or 503 error.This is particularly important for search engines, as returning a 200 status for an error page will cache the error page, rather than indicate to the crawler there's an error and to try again later.
Functionality similar to
notFound()
would be ideal, where it can be called from a layout or page triggers the nearest error page and sets the response code e.g.serverError()
serverUnavailable()
, orerror(code)
Like
notFound()
uses'not-found.js
, this may also need a corresponding server component file likeserver-error.js
, as currently the defaulterror.js
must be a client component, which may limiting.Beta Was this translation helpful? Give feedback.
All reactions