From 571c58529286703d5aab1ea0f7512b9c98f1804c Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 28 Feb 2017 23:51:11 +0000 Subject: [PATCH] HttpException: add a way to override response error message. Before this change exceptions would print the message of the error code. For example, for 500 they would print "Internal Server Error". With this change we can now override this message with something more sensible we got from the serer, for example "User is inactive." --- .../syncadapter/journalmanager/Exceptions.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.java b/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.java index 968df9c7..47e39276 100644 --- a/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.java +++ b/app/src/main/java/com/etesync/syncadapter/journalmanager/Exceptions.java @@ -43,8 +43,8 @@ public class Exceptions { public static class HttpException extends Exception implements Serializable { - public final int status; - public final String message; + final int status; + final String message; public final String request, response; @@ -65,10 +65,14 @@ public class Exceptions { } public HttpException(Response response) { + this(response, null); + } + + public HttpException(Response response, String custom_message) { super(response.code() + " " + response.message()); status = response.code(); - message = response.message(); + message = (custom_message != null) ? custom_message : response.message(); /* As we don't know the media type and character set of request and response body, only printable ASCII characters will be shown in clear text. Other octets will @@ -104,7 +108,7 @@ public class Exceptions { // format response formatted = new StringBuilder(); - formatted.append(response.protocol()).append(" ").append(response.code()).append(" ").append(response.message()).append("\n"); + formatted.append(response.protocol()).append(" ").append(response.code()).append(" ").append(message).append("\n"); headers = response.headers(); for (String name : headers.names()) for (String value : headers.values(name))