【问题标题】:GraphQL, react-apollo, Apollo 1, globally handle data.error errors with 200 HTTP code status. Not the network one.GraphQL、react-apollo、Apollo 1,全局处理 200 HTTP 代码状态的 data.error 错误。不是网络一。
【发布时间】: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


    【解决方案1】:

    据我所知,apollo-client apollo-link-error 分别对网络错误和 graphql 错误做出反应。在文档here 中了解更多信息。

    【讨论】:

      猜你喜欢
      • 2019-07-31
      • 2017-06-23
      • 2018-01-28
      • 2018-08-01
      • 2021-12-04
      • 2018-12-27
      • 2019-08-13
      • 2017-11-20
      • 1970-01-01
      相关资源
      最近更新 更多