I am trying to connect to rest service via retrofit in android application. I am getting responses. But when there is some error response from the service, conversion exception
if error in String format:
public Sring getErrorBodyAsString(RetrofitError error) {
return (String) error.getBodyAs(String.class)
}
if you need custom object:
class ErrorResponse {
@SerializedName("error")
int errorCode;
@SerializedName("msg")
String msg;
}
public T getErrorBody(RetrofitError error, Class clazz) {
return (T) error.getBodyAs(clazz);
}