/ pages / _error.page.tsx
_error.page.tsx
 1  import type { NextPageContext } from 'next';
 2  import Error from 'next/error';
 3  
 4  type ErrorPageProps = {
 5    statusCode: number;
 6  };
 7  
 8  function ErrorPage({ statusCode }: ErrorPageProps) {
 9    return <Error statusCode={statusCode} />;
10  }
11  
12  ErrorPage.getInitialProps = (ctx: NextPageContext) => {
13    const { res, err } = ctx;
14    // Inspect the status code and show the given template based off of it
15    // Default to 404 page
16    const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
17    return { statusCode };
18  };
19  
20  export default ErrorPage;