1
0
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:
Tom Hacohen 2017-04-19 11:13:10 +01:00
parent 6579ac8cf1
commit da87d14ae9
2 changed files with 9 additions and 2 deletions

View File

@ -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;

View File

@ -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]");