Catched errors shouldn't be passed to onError from apollo-link-error
Closed this issue · 0 comments
Update
My mistake, it behaves the same. I've had mistake in my own code. After creating isolated demos on codesandbox, it behaves exactly the same. I close the issue. Sorry for that.
Hey,
I'm migrating from apollo-fetch
and batchUse
, batchUseAfter
to apollo-link
and new react-apollo 3.x
.
With apollo-fetch
, If I catch an error after mutation, batchUseAfter
is not called.
Basically I can setup one global handler in batchUseAfter
that will be called only if error is not catched.
doMutation().
then(() => {
// something...
})
.catch(() => {
// handle error...
// this won't be forwarded to `batchUseAfter`
});
Is there any way to have such functionality by using apollo-link-error
?
My current setup looks +/- like this:
import { ApolloClient } from 'apollo-client';
import { BatchHttpLink } from 'apollo-link-batch-http';
import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
const errorLink = onError(({ networkError, response }) => {
console.log('networkError', networkError);
console.log('response', response);
});
new ApolloClient({
link: ApolloLink.from([
...beforeLinks,
new BatchHttpLink({
uri: getUri(),
batchInterval: 15,
...linkOptions
})
]),
cache: createCache() // I'm using InMemoryCache
});
current flow
[onError] -> [.catch handler]
desired flow
[.catch handler] ->
{if catched} -> [X] end of chain, stop propagation
{if not catched} -> [onError]
Expected Behavior
Errors from mutations that are catched, should NOT be passed into onError
from apollo-link-error
or there should be some way to "flag" such error that it's already covered.
Actual Behavior
.catch()
handlers are called and onError
from apollo-link-error
.
A simple reproduction
Using apollo-link-error
https://codesandbox.io/s/apollo-link-error-onerror-and-error-propagation-i7ub1
Using apollo-fetch
https://codesandbox.io/s/apollo-fetch-batchuseafter-and-error-propagation-ul6fz
Open console
, click Make request
button.
There should be one console.log
like in example which uses apollo-fetch
.
Related