1
1
mirror of https://github.com/primer/css.git synced 2024-12-03 15:35:29 +03:00
css/pages/_error.js

27 lines
788 B
JavaScript
Raw Normal View History

import React from 'react'
import {Heading} from '@primer/components'
import {redirectTrailingSlash} from '../docs/redirect'
export default class extends React.Component {
static getInitialProps(context) {
2019-02-19 22:51:16 +03:00
// redirect trailing slash URLs to "clean" ones without
return redirectTrailingSlash(context) || getErrorProps(context)
}
render() {
const {url, statusCode = 500} = this.props
return <>
<Heading>Whoops! Thats a {statusCode}.</Heading>
<p>
We couldnt find anything at <code>{url}</code>.
{null && <>Have you tried <a href={`/css/search?q=${encodeURIComponent(url)}`}>searching</a>?</>}
</p>
</>
}
}
function getErrorProps({req, res, err}) {
const {statusCode} = err || res
return {statusCode, url: req.url}
}