1
1
mirror of https://github.com/primer/css.git synced 2024-12-01 04:21:12 +03:00
css/pages/_error.js
2019-04-08 15:11:08 -07:00

27 lines
790 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react'
import {Heading} from '@primer/components'
import {redirectTrailingSlash} from '@primer/blueprints'
export default class extends React.Component {
static getInitialProps(context) {
// 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}
}