I'm using Retrofit library in my Android project. I have a rest server and trying to make request to it's login method. If login failed, server returns me 401 error and detailed message in json. My problem is that on my Nexus 5 with Android 5.0 it works fine, I can get the response body from the RetrofitError object. But on other devices, such as Sony Xperia M with Android 4.2.2 on the same request I'm getting No authentication challenges found
exception and the RetrofitError.response object is null. Any ideas?
UPDATE
Here is my code. I also use Robospice library.
So this is an interface:
@POST("/auth")
User logIn(@Body UserSignUp userSignUp);
Here is my Robospice request class
public class UserLoginRequest extends RetrofitSpiceRequest<User, Server> {
private UserSignUp userSignUp;
public UserLoginRequest(UserSignUp userSignUp) {
super(User.class, Server.class);
this.userSignUp = userSignUp;
}
@Override
public User loadDataFromNetwork() throws Exception {
return getService().logIn(userSignUp);
}
}
And here is my request listener:
public final class UserLoginListener implements RequestListener<User> {
@Override
public void onRequestFailure(SpiceException spiceException) {
if (spiceException.getCause() != null && ((RetrofitError) spiceException.getCause()).getBody() != null) {
Toast.makeText(LoginActivity.this, ((ResponseDto) (((RetrofitError) spiceException.getCause()).getBody())).error, Toast.LENGTH_LONG).show(); //On Nexus 5 with Android 5 this line works fine
} else {
Toast.makeText(LoginActivity.this, "Login failed", Toast.LENGTH_SHORT).show(); //On other devices I'm getting to this
}
}
@Override
public void onRequestSuccess(User user) {
//Some code here
}
}
User
is a subclass of ResponseDto
class. ResponseDto
class has only one public string field called error
.