import React from 'react' import Head from '../next-server/lib/head' import { NextPageContext } from '../next-server/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 } function _getInitialProps({ res, err, }: NextPageContext): Promise | ErrorProps { const statusCode = res && res.statusCode ? res.statusCode : err ? err.statusCode! : 404 return { statusCode } } /** * `Error` component used for handling errors. */ export default class Error

extends React.Component

{ static displayName = 'ErrorPage' static getInitialProps = _getInitialProps static origGetInitialProps = _getInitialProps render() { const { statusCode } = this.props const title = this.props.title || statusCodes[statusCode] || 'An unexpected error has occurred' return (

{statusCode}: {title}