My question is so similar to Retrofit 2.0 beta 4 response get IllegalArgumentException but its answer didn't help me.
I'm migrating from Retrofit 1.9 to 2.0.2. I'm registering my app for messaging once launches.
/**
* Synchronous method to register GCM Token on Backend Server
*
* @return true, in case of success response, false otherwise.
*/
public boolean registerGCMToken()
{
...
try
{
Call<Response> call = mService.registerGCMToken(sessionId, this.ADDITIONAL_QUERY);
final Response response = call.execute().body(); // <<< Error points here
final DefaultResponse defaultResponse = DefaultResponse.newInstance(response);
return defaultResponse.isSuccess();
}
catch (IOException ignored)
{
}
return false;
}
My interface looks like:
@GET("my/url")
Call<Response> registerGCMToken(@Header(Constant.HEADER_WILDCARD) String accessToken,
@QueryMap Map<String, String> additionalQuery);
Once I launch the app I'm getting this error:
java.lang.IllegalArgumentException: 'retrofit2.Response' is not a valid response body type. Did you mean ResponseBody?
and points to the line I mentioned above.
My newInstance method looks like:
public static final DefaultResponse newInstance(final Response response)
{
final DefaultResponse defaultResponse = new DefaultResponse();
if (response != null)
{
defaultResponse.status = response.code();
}
return defaultResponse;
}
So as you see, I need to know what is the HTTP status code. By changing Response
generic to ResponseBody
I'm not able to get http status code. What is your recommendation?