【发布时间】:2018-06-04 16:09:12
【问题描述】:
预期结果:
全局捕获data.error,就像react-apollo 告诉我这样:
Unhandled (in react-apollo) Error: GraphQL error: Not authorized for Query.myQuery
at new ApolloError (http://localhost:4000/static/js/bundle.js:3637:28)
at ObservableQuery../node_modules/apollo-client/core/ObservableQuery.js.ObservableQuery.currentResult (http://localhost:4000/static/js/bundle.js:1219:25)
at GraphQL.dataForChild (http://localhost:4000/static/js/bundle.js:41273:62)
at GraphQL.render (http://localhost:4000/static/js/bundle.js:41323:33)
at finishClassComponent (http://localhost:4000/static/js/bundle.js:50012:31)
...
实际结果:
其实我可以用这个来处理全局错误:
networkInterface.useAfter([
{
applyAfterware({ response }, next) {
console.log("response useAfter():", response);
next();
}
}
]);
但这对网络错误有好处,而不是始终为 200 HTTP 代码状态的 GraphQL 错误(如授权错误)。
版本 - apollo-client@1.9.x - react-apollo@1.4.16
【问题讨论】:
标签: reactjs graphql apollo react-apollo apollo-client