apollo-server-express给出500错误,但未显示说明

时间:2018-09-22 18:23:54

标签: express error-handling graphql apollo apollo-server

我正在尝试apollo-server-express

我在文档中找不到并且不理解的是如何显示500错误的描述。

示例:

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 }
    }
  }
})

正确表达会给我500错误。好。

但是如何显示错误说明?

我在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')
})

阿波罗中是否存在一些日志记录级别错误?

0 个答案:

没有答案