use of org.springframework.web.bind.annotation.ExceptionHandler in project nixmash-blog by mintster.
the class GlobalController method handleCategoryNotSupportedException.
@ExceptionHandler(PostCategoryNotSupportedException.class)
public ModelAndView handleCategoryNotSupportedException(HttpServletRequest request) {
ModelAndView mav = new ModelAndView();
mav.addObject("category", (String) request.getAttribute("category"));
String postName = (String) request.getAttribute("postName");
String newurl = "/post/" + postName;
mav.addObject("newurl", newurl);
mav.setViewName("errors/category");
return mav;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project judge by zjnu-acm.
the class GlobalExceptionHandler method messageExceptionHandler.
@ExceptionHandler(MessageException.class)
public ModelAndView messageExceptionHandler(MessageException ex, Locale locale) {
String message = ex.getMessage();
HttpStatus status = ex.getHttpStatus();
message = messageSource.getMessage(message, null, message, locale);
return new ModelAndView("message", Collections.singletonMap("message", message), status);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project judge by zjnu-acm.
the class GlobalExceptionHandler method handler.
@ExceptionHandler(BusinessException.class)
public ModelAndView handler(BusinessException businessException, Locale locale) {
BusinessCode code = businessException.getCode();
HttpStatus status = code.getStatus();
String message = code.getMessage();
message = messageSource.getMessage(message, businessException.getParams(), message, locale);
return new ModelAndView("message", Collections.singletonMap("message", message), status);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project wombat by PLOS.
the class ExceptionHandlerAdvisor method handleNotFound.
/**
* Directs unhandled exceptions that indicate an invalid URL to a 404 page.
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ModelAndView specifying the view
*/
@ExceptionHandler({ MissingServletRequestParameterException.class, NotFoundException.class, NotVisibleException.class, NoHandlerFoundException.class })
protected ModelAndView handleNotFound(HttpServletRequest request, HttpServletResponse response) {
Site site = siteResolver.resolveSite(request);
if (site == null && request.getServletPath().equals("/")) {
response.setHeader("Content-Type", MediaType.TEXT_HTML.toString());
return appRootPage.serveAppRoot();
}
response.setStatus(HttpStatus.NOT_FOUND.value());
String viewName = (site == null) ? "//notFound" : (site.getKey() + "/ftl/error/notFound");
return new ModelAndView(viewName);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project wombat by PLOS.
the class ExceptionHandlerAdvisor method handleException.
/**
* Handler invoked for all uncaught exceptions. Renders a "nice" 500 page.
*
* @param exception uncaught exception
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ModelAndView specifying the view
* @throws java.io.IOException
*/
@ExceptionHandler(Exception.class)
protected ModelAndView handleException(Exception exception, HttpServletRequest request, HttpServletResponse response) throws IOException {
log.error("handleException", exception);
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
Site site = siteResolver.resolveSite(request);
// For some reason, methods decorated with @ExceptionHandler cannot accept Model parameters,
// unlike @RequestMapping methods. So this is a little different...
String viewName = chooseExceptionView(site, exception);
ModelAndView mav = new ModelAndView(viewName);
StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
mav.addObject("stackTrace", stackTrace.toString());
return mav;
}
Aggregations