android - Handling server errors with Retrofit -
it great if share knowledge me! here problem - have android app. , server. of calls client needs send obtained token server legit limited amount of time. if happens token not valid more, error returned sever, new token needs obtained , need retry request.
but how can handle such behavior retrofit? thoughts?
thank in advance!
how try , make request callback, if callback failure , error message token needs obtained, request new token example:
connectioninterface.getsomestuff(object, new callback<objectpojo>() { @override public void success(objectpojo objectpojo, response response) { //success } @override public void failure(retrofiterror error) { if (error.getlocalizedmessage().equals("token expire error") connectioninterface.gettoken(); }
then in retrofit gettoken callback, if success redo getsomestuff method , if failure, let user know. example:
connectioninterface.gettoken(token, new callback<token>() { @override public void success(token token, response response) { //success , token has been added //add token request somehow... connectioninterface.updatetoken(token); connectioninterface.getsomestuff(); } @override public void failure(retrofiterror error) { //error let user know }
let me know if have other question. think easiest way of doing it.
Comments
Post a Comment