mirror of
https://github.com/etesync/android
synced 2025-06-28 10:52:35 +00:00
Journalmanager: always use the api error message when available.
This commit is contained in:
parent
6579ac8cf1
commit
da87d14ae9
@ -35,20 +35,22 @@ abstract class BaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
|
ApiError apiError = GsonHelper.gson.fromJson(response.body().charStream(), ApiError.class);
|
||||||
|
|
||||||
switch (response.code()) {
|
switch (response.code()) {
|
||||||
case HttpURLConnection.HTTP_UNAVAILABLE:
|
case HttpURLConnection.HTTP_UNAVAILABLE:
|
||||||
throw new Exceptions.ServiceUnavailableException(response, "Service unavailable");
|
throw new Exceptions.ServiceUnavailableException(response, "Service unavailable");
|
||||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
||||||
throw new Exceptions.UnauthorizedException(response, "Unauthorized auth token");
|
throw new Exceptions.UnauthorizedException(response, "Unauthorized auth token");
|
||||||
case HttpURLConnection.HTTP_FORBIDDEN:
|
case HttpURLConnection.HTTP_FORBIDDEN:
|
||||||
ApiError apiError = GsonHelper.gson.fromJson(response.body().charStream(), ApiError.class);
|
|
||||||
if (apiError.code.equals("service_inactive")) {
|
if (apiError.code.equals("service_inactive")) {
|
||||||
throw new Exceptions.UserInactiveException(response, apiError.detail);
|
throw new Exceptions.UserInactiveException(response, apiError.detail);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Fall through. We want to always throw when unsuccessful.
|
// Fall through. We want to always throw when unsuccessful.
|
||||||
}
|
}
|
||||||
throw new Exceptions.HttpException(response);
|
|
||||||
|
throw new Exceptions.HttpException(response, apiError.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -143,6 +143,11 @@ public class Exceptions {
|
|||||||
this.response = formatted.toString();
|
this.response = formatted.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
private static void appendByte(StringBuilder formatted, byte b) {
|
private static void appendByte(StringBuilder formatted, byte b) {
|
||||||
if (b == '\r')
|
if (b == '\r')
|
||||||
formatted.append("[CR]");
|
formatted.append("[CR]");
|
||||||
|
Loading…
Reference in New Issue
Block a user