Created
March 29, 2019 19:30
-
-
Save CharlyJazz/4a3573c923e8de43192aef43461d6302 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import ErrorPage from 'next/error' | |
export default Component => { | |
return class WithError extends React.Component { | |
static async getInitialProps(ctx) { | |
const props = | |
(Component.getInitialProps | |
? await Component.getInitialProps(ctx) | |
: null) || {} | |
if (props.statusCode && ctx.res) { | |
ctx.res.statusCode = props.statusCode | |
} | |
return props | |
} | |
render() { | |
if (this.props.statusCode) { | |
return <ErrorPage statusCode={this.props.statusCode} /> | |
} | |
return <Component {...this.props} /> | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment