Skip to content

Commit

Permalink
Fixed error handler: render a view only if not JSON nor PLAIN content…
Browse files Browse the repository at this point in the history
… type.
  • Loading branch information
nmihajlovski committed Mar 6, 2016
1 parent 660221b commit 02171c8
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -39,17 +39,24 @@ public Object handleError(Req req, Resp resp, Throwable error) {

if (error instanceof SecurityException) {
Log.warn("Access denied for request: " + req, "client", req.clientIpAddress());
return resp.view("login").mvc(true);
} else {
Log.error("Error occurred when handling request: " + req, error);
}

Log.error("Error occurred when handling request: " + req, error);

if (resp.contentType() == MediaType.JSON_UTF_8) {
return HttpUtils.getErrorInfo(resp, error);

} else if (resp.contentType() == MediaType.PLAIN_TEXT_UTF_8) {
return HttpUtils.getErrorMessage(resp, error);

} else {
return page(resp, error);
}
}

private Object page(Resp resp, Throwable error) {
if (error instanceof SecurityException) {
return resp.view("login").mvc(true);
} else {
Map<String, ?> errorInfo = HttpUtils.getErrorInfo(resp, error);
resp.model().put("error", errorInfo);
Expand Down

0 comments on commit 02171c8

Please sign in to comment.