core/pages/_error.tsx
2021-01-23 19:14:21 +09:00

33 lines
914 B
TypeScript

import { NextPage, NextPageContext } from 'next'
import { ErrorText } from '@utils/Constants'
const CustomError:NextPage<ErrorProps> = ({ statusCode, statusText }) => {
return <div className='h-screen flex flex-col items-center'></div>
}
export const getServerSideProps = ({ res, err }:NextPageContext) => {
let statusCode:number
// If the res variable is defined it means nextjs
// is in server side
if (res) {
statusCode = res.statusCode
} else if (err) {
// if there is any error in the app it should
// return the status code from here
statusCode = err.statusCode
} else {
// Something really bad/weird happen and status code
// cannot be determined.
statusCode = null
}
const statusText:string = ErrorText[statusCode] ?? ErrorText.DEFAULT
return { props: { statusCode, statusText } }
}
export default CustomError
interface ErrorProps {
statusCode: number
statusText?: string
}