Retrofit calls the fail () method, even if the header status code is 200

I use a modification for my backend message, and below is a snippet of my modem call:

serverObject.createEvent(Utils.getAuthHeader(), params, new Callback<CreateEventResponse>() { @Override public void success(CreateEventResponse outputObj, retrofit.client.Response response) { Log.d(TAG, outputObj.getTitle() + " is successfully created."); setResult(Activity.RESULT_OK); finish(); } @Override public void failure(RetrofitError retrofitError) { //Header status code Log.e("failure", String.valueOf(retrofitError.getResponse().getStatus())); Log.e("failure", String.valueOf(retrofitError.getResponse().getBody())); } }); 

The above code prints this in Logcat:

 04-16 16:26:11.751 25131-25131/com.android.myapp.app E/failure﹕ 200 04-16 16:26:11.751 25131-25131/com.android.myapp.app E/failure﹕ null 

who is this possible?

Can any body help why this happens.

Also I set setLogLevel(RestAdapter.LogLevel.FULL); , and therefore I can see all the values ​​in my logarithm. My answer comes from the server, but why is the call to fail () called?

Please, help!

Thanks in advance.

+7
android retrofit
source share
1 answer

The modification probably throws an exception that raises the failure method. Using:

 retrofitError.getCause() 

or do some debugging. You register the callback with CreateEventResponse, so when the body is null, you could catch a parsing exception.

+10
source share

All Articles