You could definitely have your custom logic in the lambda passed to retryWhen and return false if attempt is higher than a certain value for instance.
If you’d like to have a global WebSocket reconnection mechanism however, instead of an interceptor you can use the webSocketReconnectWhenmethod on your ApolloClient. It takes a lambda with which you can react to exceptions received in the course of the WebSocket connection, and return true (reconnect) or false (don’t reconnect).
(Note that it is deprecated because it will be replaced with the equivalent webSocketReopenWhen method in the next release).
thank you for your answer . Okay with a webSocketReconnectWhen I can also try reconnection in error case . My goal is that the retry mechanism is automatically stopped after x times of retry without success. And if possible avoid to have a custom logic inside the lambda for this .
My goal is that the retry mechanism is automatically stopped after x times of retry without success.
In fact that was the reason for having a new version of the method (webSocketReopenWhen): it takes the attempt number as a parameter . However this version is not released yet, so for now retryWhen is your best bet.
I would say having the logic in the lambda is a fine way to do this.
Regarding an interceptor: MaxRetryInterceptor you reference is on the iOS library and we don’t have the equivalent on Apollo Kotlin, but I think it should be possible to implement a reconnect policy mechanism via a custom ApolloInterceptor.