Hello, my question is about how to handle client.subscribe
errors manually.
Currently, I try to do something like:
client
.subscribe(gql`subscription{...}`, errorPolicy: 'ignore')
.subscribe({
next: (response) => {
// This doesn't work, next() doesn't get called when response has errors:
if (response.errors) {
console.log('connection lost, please wait for connection to re-establish')
}
}
})
The problem is, client.subscribe
is ignoring the errorPolicy
I’m configuring.
No matter if I set it to 'none'
, 'all'
or 'ignore'
, the subscription always triggers
client.subscribe().subscribe({error: () => {}})
and halts next
(even when the websocket message, is sent with type: "next"
)
The expected behaviour is to handle errors at subscribe({error})
with a default errorPolicy, but allow me to handle the errors manually at subscribe({next})
if i configure an errorPolicy: 'ignore'
The big problem here, is that the backend will eventually recover and start sending good messages again, but the Apollo client closes connection as soon as the error arrives, so we lose the opportunity to reconnect automatically.
Anybody knows how to handle this use-case?
additional context:
I have a React application using apollo client connecting a schema-stitched server.
The server sometimes may send error messages like this one:
{errors: [{message: "attempting reconnection #1"}]}
after a couple of those messages, the server may reconnect successfully
TL;DR:
I want to handle client.subscribe messages manually, but apollo client closes connection abruptly after error received from server (even if not fatal)