Skip to content

Commit

Permalink
Issue 151 - cover AbstractController better by refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Schoeller committed Jan 25, 2017
1 parent 2a1bec9 commit 7d39a96
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ public final ModelAndView personNotFoundError(
final HttpServletRequest request,
final PersonNotFoundException exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("personNotFound");
mav.setStatus(HttpStatus.NOT_FOUND);
final ModelAndView mav = createModelAndViewForException(
request, exception, "personNotFound", HttpStatus.NOT_FOUND);
return mav;
}

Expand All @@ -81,16 +74,8 @@ public final ModelAndView dataSetNotFoundError(
final HttpServletRequest request,
final DataSetNotFoundException exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("error");
mav.setViewName("dataSetNotFound");
mav.setStatus(HttpStatus.NOT_FOUND);
final ModelAndView mav = createModelAndViewForException(
request, exception, "dataSetNotFound", HttpStatus.NOT_FOUND);
return mav;
}

Expand All @@ -102,17 +87,32 @@ public final ModelAndView dataSetNotFoundError(
@ExceptionHandler({ Throwable.class })
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView error(final HttpServletRequest request,
final DataSetNotFoundException exception) {
final Exception exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = createModelAndViewForException(
request, exception, "error", HttpStatus.INTERNAL_SERVER_ERROR);
return mav;
}

/**
* @param request the http request being served
* @param exception the exception that occurred
* @param viewName the view we will put up in response
* @param status the status we are reporting
* @return the model and view for displaying the page
*/
private ModelAndView createModelAndViewForException(
final HttpServletRequest request, final Exception exception,
final String viewName, final HttpStatus status) {
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("error");
mav.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
mav.setViewName(viewName);
mav.setStatus(status);
return mav;
}
}

0 comments on commit 7d39a96

Please sign in to comment.