【发布时间】:2019-08-13 10:14:11
【问题描述】:
我想知道如何使用 react-apollo 在前端访问我的抛出错误?
我用于获取单个客户的简单解析器是这样的,其中args._id 是客户 ID。现在如果 id 无效,react-apollo 只会抛出 500 错误。
错误!网络错误:响应不成功:收到状态码 500
customer: async (args, req) => {
const validateId = (id) => {
return mongoose.Types.ObjectId.isValid(id)
}
if(args._id && validateId(args._id)){
try {
const customer = await Customer
.findById(args._id)
return transformCustomer(customer)
}
catch (err) {
throw err
}
}
else {
throw new Error("error")
}
},
我尝试使用 errorPolicy="all" 并访问 error.graphQLErrors,但这不起作用,因为它会引发 500 错误。
无法读取未定义的属性“graphQLErrors”
【问题讨论】:
标签: reactjs graphql apollo react-apollo