Better error pages and fix checkout admin issue
parent
249d520070
commit
475b88626e
@ -1,20 +0,0 @@
|
||||
const errorMessages = {
|
||||
404: {title: 'Page not found', message: 'Unfortunately that page could not be found. If you followed a link to get here, please let the owner of the link know that they need to update it.'},
|
||||
[undefined]: {title: 'Unknown error', message: "We're not exactly sure what happened"}
|
||||
}
|
||||
|
||||
export default function ErrorDisplay({error}){
|
||||
const defaults = errorMessages[error.status]
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2>{error.name || defaults.title}</h2>
|
||||
<p>{error.message || defaults.message}</p>
|
||||
{process.env.NODE_ENV === 'development' && (
|
||||
<pre>
|
||||
{JSON.stringify(error, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
@ -1,18 +1,49 @@
|
||||
import React from 'react'
|
||||
import ErrorDisplay from '~/components/errorDisplay'
|
||||
import getConfig from 'next/config'
|
||||
|
||||
const ErrorPage = ({error}) => (
|
||||
<ErrorDisplay error={error} />
|
||||
)
|
||||
const {publicRuntimeConfig} = getConfig()
|
||||
|
||||
ErrorPage.getInitialProps = ({ res, err }) => {
|
||||
let error = err || {};
|
||||
const ErrorPage = ({error}) => {
|
||||
const env = publicRuntimeConfig.SOS_ENV
|
||||
if (!error)
|
||||
return (
|
||||
<>
|
||||
<h2>Not Found</h2>
|
||||
<p>This page was not found</p>
|
||||
</>
|
||||
)
|
||||
|
||||
if(!error)
|
||||
error = new Error('Server Error')
|
||||
return (
|
||||
<>
|
||||
<h2>{error.name}</h2>
|
||||
<p>{error.message}</p>
|
||||
{env === 'development' && (
|
||||
<>
|
||||
{error.stack && (
|
||||
<p>
|
||||
<pre>
|
||||
{error.stack}
|
||||
</pre>
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
<pre>
|
||||
{JSON.stringify(error, null, 2)}
|
||||
</pre>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
ErrorPage.getInitialProps = ({ctx: {err, req, res}}) => {
|
||||
if(!err) return {error: null}
|
||||
|
||||
if(res)
|
||||
err.status = res.statusCode
|
||||
|
||||
error.status = (err && err.status) || (res ? res.statusCode : (error.statusCode || 404))
|
||||
return { error }
|
||||
return { error: err }
|
||||
}
|
||||
|
||||
export default ErrorPage
|
||||
|
Loading…
Reference in New Issue