i'm using retrofit return observable result of rest api call server. usual request timeout exception occurs , observable stops executing. how resubscribe of retry if exception of specific type
myobservable .subscribe(new subscriber<something> sub(){ @override void onnext(something something){ //do something } @override void onerror(throwable e){ //retry , resend call server if e request timeout exception }
you can use retry operator.
example:
myobservable .retry((retrycount, throwable) -> retrycount < 3 && throwable instanceof sockettimeoutexception) .subscribe(new subscriber<something> sub(){ @override void onnext(something something){ //do something } @override void onerror(throwable e){ }
in example resubscribe when there sockettimeoutexception
max 3 times.
or without lambda:
myobservable .retry(new func2<integer, throwable, boolean>() { @override public boolean call(integer retrycount, throwable throwable) { return retrycount < 3 && throwable instanceof sockettimeoutexception; } }) .subscribe(new subscriber<something> sub(){ @override void onnext(something something){ //do something } @override void onerror(throwable e){ }
Comments
Post a Comment