预期结果:
全球范围内的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
<2.0并不容易实现。但是,在2.0中,您可以使用apollo-link-error
分别对网络错误和graphql错误做出反应。在文档here中了解更多信息。