java - Can't catch the custom exception in the onError() method in Rxjava -
i want deal exception myself , example ,show proper toast, write responsefunc
below:
public final class responsefunc<t> implements func1<baseresponse<t>, observable<t>> { @override public observable<t> call(baseresponse<t> response) { if (!response.issuccess()) { switch (response.geterror().getcode()) { case 404: { throw new errorresponseexception("say sorry")); } // , many other case here 404 500... default: { return observable.error(new errorresponseexception(response.geterror().getmessage())); } } } else { return observable.just(response.getdata()); } } }
ps: here errorresponseexception
extends runtimeexception
but can't message "say sorry" or other exceptions thrown myself in subscriber's onerror()
method (or observer's onerror()
method).
when print stack traces ,it shows original exception , error message
for more details : basic response quite simple , :
{data : t , error{code : int , message : string}, succeed : boolean}
and use responsefunc
in flatmap()
method everywhere :
service.dosomething() .flatmap(new responsefunc<>()) .compose(new schedulertransformer<>());
i don't know going wrong.but if feels wrong , ðŸ˜
could plz give me advices, thx in advance.
Comments
Post a Comment