Skip to content

Commit

Permalink
fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
greenlaw110 committed Aug 31, 2014
1 parent 5215b95 commit 53610b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setMessageSource(MessageSource messageSource) {

boolean customErrorPages;

private InternalServerErrorVisitor internalServerErrorVisitor;
private static InternalServerErrorVisitor internalServerErrorVisitor;

@Autowired
public RythmExceptionHandler(RythmConfigurer conf) {
Expand All @@ -62,6 +62,10 @@ public void setInternalServerErrorVisitor(InternalServerErrorVisitor errorVisito
internalServerErrorVisitor = errorVisitor;
}

static InternalServerErrorVisitor getInternalServerErrorVisitor() {
return internalServerErrorVisitor;
}

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(Exception e, HttpServletResponse response) throws Exception {
if (e instanceof Result) {
Expand All @@ -83,7 +87,7 @@ public ModelAndView defaultErrorHandler(Exception e, HttpServletResponse respons
modelAndView.addObject("statusCode", statusCode);
modelAndView.addObject("message", reason);
modelAndView.addObject("attachment", e);
modelAndView.setViewName("errors/prod/error.html");
modelAndView.setViewName("errors/prod/500.html");
return modelAndView;
}
if (!StringUtils.hasLength(reason)) {
Expand All @@ -102,7 +106,7 @@ public ModelAndView defaultErrorHandler(Exception e, HttpServletResponse respons
modelAndView.addObject("statusCode", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
modelAndView.addObject("message", "Internal server error");
modelAndView.addObject("attachment", e);
modelAndView.setViewName("errors/prod/error.html");
modelAndView.setViewName("errors/prod/500.html");
return modelAndView;
}
throw e;
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/rythmengine/spring/web/RythmView.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,16 @@ protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletR
}
} catch (RythmException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
engine.render(response.getOutputStream(), "errors/500.html", e);
if (engine.isDevMode()) {
engine.render(response.getOutputStream(), "errors/500.html", e);
} else {
RythmExceptionHandler.getInternalServerErrorVisitor().visit(e);
Map<String, Object> args = new HashMap<String, Object>();
args.put("message", "Internal server error");
args.put("attachment", e);
String s = engine.render("errors/prod/500.html", args);
IO.writeContent(s, response.getWriter());
}
} finally {
RythmEngine.renderCleanUp();
}
Expand Down

0 comments on commit 53610b6

Please sign in to comment.