import React from 'react' import Head from 'next-server/head' import { NextPageContext } from 'next-server/dist/lib/utils' const statusCodes: { [code: number]: string } = { 400: 'Bad Request', 404: 'This page could not be found', 405: 'Method Not Allowed', 500: 'Internal Server Error', } export type ErrorProps = { statusCode: number title?: string } /** * `Error` component used for handling errors. */ export default class Error

extends React.Component

{ static displayName = 'ErrorPage' static getInitialProps({ res, err, }: NextPageContext): Promise | ErrorProps { const statusCode = res && res.statusCode ? res.statusCode : err ? err.statusCode! : 404 return { statusCode } } render() { const { statusCode } = this.props const title = this.props.title || statusCodes[statusCode] || 'An unexpected error has occurred' return (

{statusCode}: {title}