Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add next/error #1040

Merged
merged 1 commit into from
Feb 8, 2017
Merged

Add next/error #1040

merged 1 commit into from
Feb 8, 2017

Conversation

nkzawa
Copy link
Contributor

@nkzawa nkzawa commented Feb 8, 2017

This PR enables to import default error page component with next/error.
It's intended to be used for displaying errors occurred on getInitialProps like #746 (comment), thanks to @dizlexik for sharing his workaround !

Fixes #746

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@rauchg rauchg merged commit 9348762 into master Feb 8, 2017
@rauchg rauchg deleted the add/expose-error branch February 8, 2017 19:59
@sedubois
Copy link
Contributor

@nkzawa Is there any recommendation on how to display this error page, in case it's not triggered in getInitialProps?

For example with Apollo client:

  • the render method might receive a data.error parameter in case of some generic issue
  • or simply, we may issue a GraphQL query which doesn't give any result, in which case render will receive empty data. In this case I'd like to display the error page you provide with a status of 404.

@nkzawa
Copy link
Contributor Author

nkzawa commented Feb 14, 2017

@sedubois You mean to render the error page on custom server ? It would be something like this.

res.statusCode = 404
app.renderError(err, req, res, pathname, query)

But basically, I think you should use getInitialProps rather than fetching data on custom server.

@sedubois
Copy link
Contributor

sedubois commented Feb 14, 2017

@nkzawa I don't mean custom server, but simply rendering the error page from within a component. Not from getInitialProps but instead from e.g componentWillMount.

  componentWillMount() {
    if (this.props.XXX === YYY) {
      // render error page
    }
  }

@nkzawa
Copy link
Contributor Author

nkzawa commented Feb 14, 2017

@sedubois I think you can just do that on render ?

render () {
  if (this.props.XXX === YYY) {
     return <ErrorPage statusCode={500} />
  }
  ...
}

@sedubois
Copy link
Contributor

Thanks, that works. I was rather wondering how to render only that component. But that will do for now.

@timneutkens timneutkens mentioned this pull request Feb 15, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants