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."
pull/2/head
Tom Hacohen 7 years ago
parent fc939a3cbe
commit 571c585292

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

Loading…
Cancel
Save