Apollo-client: Possible Unhandled Promise Rejection

Created on 19 Mar 2017  路  17Comments  路  Source: apollographql/apollo-client

Apollo 1.0.0-rc.4. React Native 0.42.3

I have some query:

client.query({
  query: SOME_QUERY,
  options: {
    fetchPolicy: 'network-only',
  },
  variables: { ... },
}).then(result => {

}).catch(error => {
  console.log(error)
});

And when I turn off my internet connection I am getting this error message:
Possible Unhandled Promise Rejection (id: 0):Network error: Network request failed

Most helpful comment

@helfer please reopen this issue. I am getting this error again but now with refetch function. My code

const withData = graphql(PROFILE_QUERY, {
  options: ({ currentUserId }) => ({
    variables: { id: currentUserId }
  }),
  props: ({ ownProps, data: { loading, user, error, refetch } }) => ({
    loading,
    user,
    error,
    refetch
  })
});

const withHomeHandlers = withHandlers({
  refetchUser: props => async() => {
    const { setRefresh, refetch } = props;
    setRefresh(true);
    await refetch();
    setRefresh(false);
  }
});

I see my profile, switch off my internet connection and make refetch then I am see Network Error at props.error. This is fine I can handle errors but I think query is still running and after query timeout I got the same error as above.

All 17 comments

@jurajkrivda Do you have a stack trace for this? It could be due to a recent change that we could easily revert.

@helfer here you are

Possible Unhandled Promise Rejection (id: 0):
Network error: Network request failed
Error: Network error: Network request failed
    at new ApolloError (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:49611:32)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:50833:32
    at tryCallOne (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:16998:12)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:17084:15
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:6432:19
    at Object.callTimer (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5648:9)
    at Object.callImmediatesPass (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5734:27)
    at Object.callImmediates (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5744:30)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5515:34
    at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5368:5)

That stack trace is not very useful, bcause it doesn't have source maps. Are you getting the same with rc.2?

I'm guessing this is the change that caused it: https://github.com/apollographql/apollo-client/pull/1133/files

Could you help me verify it conclusively by editing the file in your node_modules/apollo-client/lib directory to add the catch back in? If the error doesn't appear any more, then this was the change responsible for what you're seeing.

If it doesn't work, a reproduction with https://github.com/apollographql/react-apollo-error-template would be much appreciated.

I don`t have a directory lib at node_modules/apollo-client.
With rc.2 it works.

Oh, I see. In that case you probably have the umd bundle.

In the file that is under main in package.json, find the QueryManager.prototype.startQuery function and add back a .catch(function (error) { return undefined; }); after this.fetchQuery(queryId, options).

It works now.

Ok, in that case I will revert the PR and release a new version with the fix in a few hours.

Thank you @helfer

@helfer please reopen this issue. I am getting this error again but now with refetch function. My code

const withData = graphql(PROFILE_QUERY, {
  options: ({ currentUserId }) => ({
    variables: { id: currentUserId }
  }),
  props: ({ ownProps, data: { loading, user, error, refetch } }) => ({
    loading,
    user,
    error,
    refetch
  })
});

const withHomeHandlers = withHandlers({
  refetchUser: props => async() => {
    const { setRefresh, refetch } = props;
    setRefresh(true);
    await refetch();
    setRefresh(false);
  }
});

I see my profile, switch off my internet connection and make refetch then I am see Network Error at props.error. This is fine I can handle errors but I think query is still running and after query timeout I got the same error as above.

@helfer +1 I'm also getting this same issue using refetch()

@helfer Can we reopen this issue? I'm also getting the same error when using refetch()

@areiterer Can you please create a minimal reproduction on https://codesandbox.io?

I'm getting the same errors with use a network-only and resetting (this.props.client.resetStore()) the store, as I understand this should _refetch_ all queries.

I'm returning to login screen so allot of views getting unmounted, my 2 cents are that there is a network call going on in the background but the view initiated the _refetch_ it is now unmounted?

So please reopen this issue, as I can't find any similar open issues.

Or should I follow status via https://github.com/apollographql/apollo-client/pull/3157? Maybe will solve this too?

I am getting the same error. @helfer

@maqen @quanological

What versions of apollo-client and react-apollo are you using? Could you provide a minimal reproduction case on codesandbox.io using the newest 2.1.0-beta?

For everyone seeing this in refetch, see #3631

Was this page helpful?
0 / 5 - 0 ratings