Next.js Discord

Discord Forum

Display 500.tsx error component in dev mode

Unanswered
Tan posted this in #help-forum
Open in Discord
TanOP
Display 500.tsx error component in dev mode

19 Replies

TanOP
Hi there! My backend sends a 500 http response and my next js shows this in dev mode:
But i'd like to try to make nextJS show the actual 500.tsx error which happens in prod
so is there some CLI argument/nextJS config option to make it show 500.tsx in dev mode?
Bighead carp
Are you using app router or pages router?
@Bighead carp Are you using app router or pages router?
TanOP
pages router, yes, the one with directory/file based routing
in prod it looks like this:
@Bighead carp https://nextjs.org/docs/pages/building-your-application/routing/custom-error#500-page
TanOP
ye well it says
pages/_error.js is only used in production. In development you’ll get an error with the call stack to know where the error originated from.
other than that didnt find anything...
is my only option to build and run the build
Bighead carp
Can you show me the line it's failing on
@Bighead carp Can you show me the line it's failing on
TanOP
export const getServerSideProp = async (...) => {
  await axios.get(...);
}
something like this - theres an axious GET request in getServerSideProps that fails today 500
Bighead carp
You could manually catch the exception and move them to the 500 page
TanOP
ye but its not up to me...
i need to fix something that pops up in 500.tsx
@Bighead carp You could manually catch the exception and move them to the 500 page
TanOP
would this be an ok way to redirect the user to the example.com/500 for server side errors?

in 500.tsx
export default function Error404Page() {
  ...
    useEffect(() => {
    if (router.asPath !== '/500') {
      router.push('/500');
    }
  }, []);
  ...
  return ...
}
basically everytime 500.tsx component pops up (for 500 HTTP errors) i check the url and if its not site.com/500 then i do a client side transition to it
i believe getServerSideProps' redirect return is not supported for error pages so i cant redirect like that 🤔