बदल देता है। जब सर्वर से 200 ठीक कोड प्राप्त करने, सब कुछ ठीक काम कर रहा है। लेकिन मैं इस तरह के कोड के रूप में भी नहीं ठीक प्रतिक्रियाओं, के साथ सौदा करना चाहते हैं 401 तो, मैं वास्तव में क्या कार्रवाई करते हैं और उपयुक्त डेटा प्रदर्शित करने के लिए यह पता लगाने की त्रुटि प्रतिसाद कोड प्राप्त करने के लिए है:रेट्रोफिट 2: responseBodyConverter मैं <a href="http://square.github.io/retrofit/" rel="nofollow noreferrer">Retrofit</a> के संस्करण (अब 2.0.0-beta4 के रूप में) नवीनतम उपयोग कर रहा हूँ वस्तु शून्य पर
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
if (response != null && !response.isSuccess() && response.errorBody() != null) {
Converter<ResponseBody, APIError> errorConverter = retrofit.responseBodyConverter(APIError.class, new Annotation[0]);
try {
APIError error = errorConverter.convert(response.errorBody());
Toast.makeText(getContext(), "code = " + error.getCode() + ", status = " + error.getStatus(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
} else if (null != response) {
if (response.isSuccess()) {
LoginResponse loginResponse = response.body();
Toast.makeText(getContext(), "Successful login: " + loginResponse.getId(), Toast.LENGTH_SHORT).show();
}
}
}
APIError.java
public class APIError {
String name;
int status;
String message;
int statusCode;
String code;
String stack;
public String getName() {
return name;
}
public int getStatus() {
return status;
}
public String getCode() {
return code;
}
}
सर्वर त्रुटि प्रतिसाद
{
"error": {
"name": "Error",
"status": 401,
"message": "login failed",
"statusCode": 401,
"code": "LOGIN_FAILED",
"stack": "Error: login failed"
}
}
लेकिन,210 रिटर्न शून्य मान के साथ एक वस्तु। मैं similar posts देखा है, लेकिन यह मदद नहीं की।
क्या कोड के साथ गलत क्या है?
__futurestud.io__ सबसे अच्छा ** रेट्रोफिट ** ट्यूटोरियल प्रदान करता है –