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

apollo-server-express gives 500 error but does not show description #1710

Closed
frederikhors opened this issue Sep 22, 2018 · 3 comments
Closed

Comments

@frederikhors
Copy link

I'm trying apollo-server-express.

What I don't find in docs and don't understand is how to show description of a 500 error.

Example:

const serverApollo = new ApolloServer({
  typeDefs,
  resolvers,
  context: ({ req }) => {
    // req.user is undefined here
    console.log('*req', req) // -> no req.user present!
    return {
      currentUser: { id: req.user.id }
    }
  }
})

Correctly express gives me a 500 error. Good.

But how to show the error description?

I have this code in app.js:

...
serverApollo.applyMiddleware({ app })

// -> It doesn't call anything below, why?
// This code is a standard Express template for error handling: http://expressjs.com/en/guide/error-handling.html
app.use(function (req, res, next) {
  next(createError(404))
})

app.use(function (err, req, res, next) {
  console.log('err:', err)
  res.locals.message = err.message
  res.locals.error = req.app.get('env') === 'development' ? err : {}
  res.status(err.status || 500)
  res.render('error')
})

Is there some logging level error in Apollo?

@marcospgp

This comment has been minimized.

@spyshower

This comment has been minimized.

@abernix
Copy link
Member

abernix commented Jul 29, 2019

The above error should surface just fine within the errors property of the GraphQLResponse. In "production" (that is, when process.env.NODE_ENV is set to production), the actual error message will be redacted and output as INTERNAL_SERVER_ERROR, but during development you should be able to see the full error.

If you'd like to change the behavior to ensure that the full error is also shown in production, you can set debug: true on the ApolloServer constructor. If you'd like to output the full error elsewhere, consider using the didEncounterErrors life-cycle method (#2719) or outputting the error to a logger within formatError.

If anyone continues to struggle with this, please feel free to open a new issue and include a runnable reproduction demonstrating the problem.

Unrelated to the original post, if anyone is upset with the state of our documentation or error handling, feel free to open issues targeting specific areas needing improvement with concrete suggestions of what needs improvement. Otherwise, it's unlikely that the documentation or errors will merely "improve".

@abernix abernix closed this as completed Jul 29, 2019
@apollographql apollographql locked and limited conversation to collaborators Jul 29, 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

No branches or pull requests

4 participants