GraphQL,react-apollo,Apollo 1,全局处理200个HTTP代码状态的data.error错误。不是网络的。

问题描述 投票:0回答:1

预期结果:

全球范围内的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(如授权)。

版本 - [email protected] - [email protected]

reactjs graphql apollo react-apollo apollo-client
1个回答
0
投票

据我所知,apollo-client <2.0并不容易实现。但是,在2.0中,您可以使用apollo-link-error分别对网络错误和graphql错误做出反应。在文档here中了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.