Create a custom 500 error page for my Next.js website?

Answered
looper003 asked this question 10 months ago
looper003 on Dec 5, 2021

How do I change what the 500 error page looks like for my Next.js application?

1 suggested answers
itsbambi on Dec 8, 2021

To add a custom layout and styling for your 500 page, you'll need to create a /pages/_error.js file:

cd pages && touch _error.js

In development mode, a stack error will be shown that tells you what the error is.

In the production environment, the contents of the /pages/_error.js file will be shown.

Some example code for that page could look like this:

export default class extends Component {
  render () {
    return (
      <div style={{padding: "15px"}}>
        <span>An error occurred.</span>
      </div>
    )
  }
}

You can add whatever message, styling, etc. to the page you'd like.

0 replies
Answered