How to get statusCode from try/catch on sync request
cutiko opened this issue · comments
Greetings
Im following the doc about the sync request https://github.com/orhanobut/wasp/wiki/Sync-Request is working. But I cant figure it out how to handle the try/catch properly.
First I realize that any error would crash the app. So according with documentation "Use try/catch block to handle exceptions". Off course the try/catch rescue the app from crashing, but I cant know what is the error number. So I added the Callback inside the try/catch, very silly of me cause the try/catch handle the exception first, hence the callback is never executed.
I have being looking at the library classes to understand how to handle the error. By example the Callback lead me to a dead end cause is an Interface. The WaspError gave me some clues, but Im still bouncing.
How can I get the getStatusCode? This is what I have done so far:
try {
User user = service.login();
}catch (RuntimeException exception) {
Log.d("ERROR", exception.getCause().toString() + " " + exception.getLocalizedMessage() + " " + exception.getMessage() + " " + exception.getCause().getMessage());
}
What I need is something like what is done with the Callbacks:
@Override
public void onError(WaspError error) {
//This is what I need
error.getResponse().getStatusCode();
}
If I could get any help please, thanks.