React-apollo: Right way to handle ApolloErrors

Created on 3 Nov 2017  路  11Comments  路  Source: apollographql/react-apollo

Hi, I have one pretty simple, but important question about error handling in react-apollo.

My problem is: I execute my query in GraphiQL and get an error in response, but also I have some data, that can be queried without error.

untitled

So I want to show to user this successfully queried data and show an error in section with error data, but in Apollo-connected component I can get only errors block, without successfully queried data

You can reproduced it like this:

{
  empireHero: hero(episode: 'works fine with this argument') {
    name
  }
  jediHero: hero(episode: 'failed with this argument') {
    name
  }
}

All you query will be 'invalid', instead of getting error and data sections, you will get only error section.
Probably I trying to make something wrong? Can you try help me with this problem?

Version

  • apollo-client@ 2.0.1
  • react-apollo@ 2.0.0

Most helpful comment

@noeljackson, the problem is not that data.error is undefined - I don't get data section when i use errorPolicy: all. It works absolutely the same as any other errorPolicy value. Seems like it's even not affected my query

image

If I executed the same query with GraphiQL I have error and data sections, but in Apollo I can't see data section

image

All 11 comments

Hi @EugeneDraitsev! react-apollo's default policy is to treat any GraphQL errors as runtime errors and to discard the data. To customize this policy, learn more here.

Hi @peggyrayzis, thanks for quick response. I tried to set my options like

{
    variables: { appLang, tenant, manufacturers },
    errorPolicy: 'all', // Also tried all other values
}

But I still can't see any data, when query has errors (and doublechecked that I get data in GraphiQL)

When I get error in my callQueue and still can't see successfully fetched contentInfo data:
untitled

When I don't have any errors:
screenshot_4

Probably I still missed something, or I should override errorPolicy by another way?

Any updates about it?

I can add some more information to this. data.error is returned undefined when using errorPolicy: 'all' Only after removing errorPolicy at all was I able to get errors passing through.

@noeljackson, the problem is not that data.error is undefined - I don't get data section when i use errorPolicy: all. It works absolutely the same as any other errorPolicy value. Seems like it's even not affected my query

image

If I executed the same query with GraphiQL I have error and data sections, but in Apollo I can't see data section

image

@noeljackson I have the same... very strange...

I have an identical problem. Did anyone get to know how to fetch errors and data from the responce?

I'm having the same issue

I'm running into this as well.

For full error handling details, please see the Error handling section of the docs. If anything isn't clear in the docs (or isn't working), please let us know in a new issue. Thanks!

Was this page helpful?
0 / 5 - 0 ratings