Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

useQuery's onError callback is never fired #3287

Closed
kasvtv opened this issue Jul 29, 2019 · 5 comments · Fixed by #3339
Closed

useQuery's onError callback is never fired #3287

kasvtv opened this issue Jul 29, 2019 · 5 comments · Fixed by #3339
Assignees
Labels
has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@kasvtv
Copy link

kasvtv commented Jul 29, 2019

Intended outcome:
When a request made by useQuery fails, onError is fired

Actual outcome:
It never fires, whether it's a connection error, or a non-200 response

Version
@apollo/react-hooks 0.1.0-beta.10 (Can't get beta.11 to work at all due to #3270)

System:
OS: Windows 10
Binaries:
Node: 11.4.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.12.3 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.17763.1.0
npmPackages:
apollo-server-express: ^1.3.2 => 1.4.0

(This happens both on Windows and on a Linux Docker container though)

@hwillson hwillson self-assigned this Jul 29, 2019
@hwillson hwillson added this to the Release 3.0 milestone Jul 29, 2019
@alfiehub
Copy link

For me it seems to be the opposite. onError is actually executed three or four times. onError gets executed every time data or loading is updated.

Using version 0.1.0-beta.11.

@hwillson
Copy link
Member

hwillson commented Aug 5, 2019

@kasvtv @alfiehub Can you try @apollo/[email protected] and let me know if that helps? I'm having difficulty re-creating either of these issues, so if that doesn't help would you mind putting together a small runnable repro?

@alfiehub
Copy link

alfiehub commented Aug 6, 2019

@hwillson I've forked a sandbox I found in another issue and tried to recreate the multiple onError calls problem using 0.1.0-beta.12.
https://codesandbox.io/s/apolloreact-hooks-multiple-onerror-calls-p1ifr

It seems to still be occurring as you can see in the console.

@riccoski
Copy link

riccoski commented Aug 6, 2019

@hwillson I've forked a sandbox I found in another issue and tried to recreate the multiple onError calls problem using 0.1.0-beta.12.
https://codesandbox.io/s/apolloreact-hooks-multiple-onerror-calls-p1ifr

It seems to still be occurring as you can see in the console.

For me on the sandbox on beta 11 it actually on fires once. But 12 It fires twice + the onCompleted gets fired.

I wonder whether it's because the of the cleanup function

@hwillson hwillson removed this from the Release 3.0 milestone Aug 6, 2019
@hwillson hwillson added has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository and removed reproduction-needed labels Aug 9, 2019
@hwillson
Copy link
Member

hwillson commented Aug 9, 2019

Thanks for the reproduction @alfiehub - I'm looking into this now.

hwillson added a commit that referenced this issue Aug 10, 2019
1. It prevents the `onError` callback from unnecessarily being
called multiple times in a row.

2. It migrates all peer and dev deps to use `apollo-client`
2.6.4. Apollo Client 2.6.4 provides a fix for last result
error tracking
(apollographql/apollo-client@c44e821),
which fixes the long standing React Apollo issue of `refetch`
not setting `loading` state properly. Calling `refetch` will
now first set `loading` to `true`.

These fixes are bundled together, as verifying that `onError`
is working properly requires being able to make sure results
after a refetch that don't have an error, are handled properly.

Fixes #3331.
Fixes #3287.
Fixes #2559.
Fixes #321.

(and probably fixes others!)
hwillson added a commit that referenced this issue Aug 10, 2019
)

* This commit helps address 2 main issues:

1. It prevents the `onError` callback from unnecessarily being
called multiple times in a row.

2. It migrates all peer and dev deps to use `apollo-client`
2.6.4. Apollo Client 2.6.4 provides a fix for last result
error tracking
(apollographql/apollo-client@c44e821),
which fixes the long standing React Apollo issue of `refetch`
not setting `loading` state properly. Calling `refetch` will
now first set `loading` to `true`.

These fixes are bundled together, as verifying that `onError`
is working properly requires being able to make sure results
after a refetch that don't have an error, are handled properly.

Fixes #3331.
Fixes #3287.
Fixes #2559.
Fixes #321.

(and probably fixes others!)

* Changelog update

* Silence extra CI warnings to troubleshoot test issues
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants