1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/pages/_error-debug.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-10-19 12:41:45 +00:00
import React from 'react'
import ansiHTML from 'ansi-html'
2016-10-19 12:41:45 +00:00
import Head from 'next/head'
2016-10-25 08:16:54 +00:00
import style from 'next/css'
2016-10-19 12:41:45 +00:00
export default class ErrorDebug extends React.Component {
static getInitialProps ({ err }) {
const { message, module } = err
return { message, path: module.rawRequest }
}
render () {
const { message, path } = this.props
return <div className={styles.errorDebug}>
2016-10-19 12:41:45 +00:00
<Head>
<style dangerouslySetInnerHTML={{ __html: `
body {
background: #a6004c;
2016-10-19 12:41:45 +00:00
margin: 0;
}
`}} />
</Head>
<div className={styles.heading}>Error in {path}</div>
<pre className={styles.message} dangerouslySetInnerHTML={{ __html: ansiHTML(encodeHtml(message)) }} />
2016-10-19 12:41:45 +00:00
</div>
}
}
const encodeHtml = str => {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;')
}
const styles = {
body: style({
background: '#a6004c',
2016-10-19 12:41:45 +00:00
margin: 0
}),
2016-10-19 12:41:45 +00:00
errorDebug: style({
2016-10-19 12:41:45 +00:00
height: '100%',
padding: '16px',
boxSizing: 'border-box'
}),
2016-10-19 12:41:45 +00:00
message: style({
fontFamily: '"SF Mono", "Roboto Mono", "Fira Mono", menlo-regular, monospace',
2016-10-19 12:41:45 +00:00
fontSize: '10px',
color: '#fff',
margin: 0
}),
2016-10-19 12:41:45 +00:00
heading: style({
fontFamily: '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif',
2016-10-19 12:41:45 +00:00
fontSize: '13px',
fontWeight: 'bold',
color: '#ff84bf',
2016-10-19 12:41:45 +00:00
marginBottom: '20px'
})
}
ansiHTML.setColors({
reset: ['fff', 'a6004c'],
darkgrey: '5a012b',
yellow: 'ffab07',
green: 'aeefba',
magenta: 'ff84bf',
blue: '3505a0',
cyan: '56eaec',
red: '4e053a'
})