|
| 1 | +import React from 'react' |
| 2 | +import Head from './head' |
| 3 | + |
| 4 | +export default class Error extends React.Component { |
| 5 | + static getInitialProps ({ res, xhr }) { |
| 6 | + const statusCode = res ? res.statusCode : (xhr ? xhr.status : null) |
| 7 | + return { statusCode } |
| 8 | + } |
| 9 | + |
| 10 | + render () { |
| 11 | + const { statusCode } = this.props |
| 12 | + const title = statusCode === 404 |
| 13 | + ? 'This page could not be found' |
| 14 | + : (statusCode ? 'Internal Server Error' : 'An unexpected error has occurred') |
| 15 | + |
| 16 | + return <div style={styles.error}> |
| 17 | + <Head> |
| 18 | + <meta name='viewport' content='width=device-width, initial-scale=1.0' /> |
| 19 | + </Head> |
| 20 | + <div> |
| 21 | + <style dangerouslySetInnerHTML={{ __html: 'body { margin: 0 }' }} /> |
| 22 | + {statusCode ? <h1 style={styles.h1}>{statusCode}</h1> : null} |
| 23 | + <div style={styles.desc}> |
| 24 | + <h2 style={styles.h2}>{title}.</h2> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +const styles = { |
| 32 | + error: { |
| 33 | + color: '#000', |
| 34 | + background: '#fff', |
| 35 | + fontFamily: '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif', |
| 36 | + height: '100vh', |
| 37 | + textAlign: 'center', |
| 38 | + display: 'flex', |
| 39 | + flexDirection: 'column', |
| 40 | + alignItems: 'center', |
| 41 | + justifyContent: 'center' |
| 42 | + }, |
| 43 | + |
| 44 | + desc: { |
| 45 | + display: 'inline-block', |
| 46 | + textAlign: 'left', |
| 47 | + lineHeight: '49px', |
| 48 | + height: '49px', |
| 49 | + verticalAlign: 'middle' |
| 50 | + }, |
| 51 | + |
| 52 | + h1: { |
| 53 | + display: 'inline-block', |
| 54 | + borderRight: '1px solid rgba(0, 0, 0,.3)', |
| 55 | + margin: 0, |
| 56 | + marginRight: '20px', |
| 57 | + padding: '10px 23px 10px 0', |
| 58 | + fontSize: '24px', |
| 59 | + fontWeight: 500, |
| 60 | + verticalAlign: 'top' |
| 61 | + }, |
| 62 | + |
| 63 | + h2: { |
| 64 | + fontSize: '14px', |
| 65 | + fontWeight: 'normal', |
| 66 | + margin: 0, |
| 67 | + padding: 0 |
| 68 | + } |
| 69 | +} |
0 commit comments