Domanda

I am using retrofit for my backend communication and below it the snippet of my retrofit 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 the 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 please help why is this happening.

Also I have set setLogLevel(RestAdapter.LogLevel.FULL); and so i can see every values in my logcat. My response is coming correct from the server but why is failure() getting called?

Please help!

Thanks in advance.

È stato utile?

Soluzione

Probably retrofit throws an exception which call failure method. Use:

retrofitError.getCause()

or make some debugging. You register callback with CreateEventResponse so when body is null you could have caught parse exception.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top