コード例 #1
0
 @RequestMapping(ERROR_PATH)
 String error(HttpServletRequest request, Model model) {
   Map<String, Object> errorMap =
       errorAttributes.getErrorAttributes(new ServletRequestAttributes(request), false);
   model.addAttribute("errors", errorMap);
   return "error";
 }
コード例 #2
0
  @RequestMapping(value = ERROR_PATH)
  public ResponseEntity<Map<String, Object>> error(HttpServletRequest request, Locale locale) {
    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    Map<String, Object> body = errorAttributes.getErrorAttributes(requestAttributes, true);

    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (Objects.nonNull(body.get("status"))) {
      try {
        status = HttpStatus.valueOf((Integer) body.get("status"));
      } catch (Exception ignore) {
      }
    }

    String message =
        messageSource.getMessage("error." + status, null, ERROR_DEFAULT_MESSAGE, locale);
    if (StringUtils.hasText(message)) {
      body.put("message", message);
    }

    return ResponseEntity.status(status).body(body);
  }
コード例 #3
0
 private Map<String, Object> getErrorAttributes(
     HttpServletRequest request, boolean includeStackTrace) {
   RequestAttributes requestAttributes = new ServletRequestAttributes(request);
   return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
 }
コード例 #4
0
ファイル: ErrorController.java プロジェクト: birkana/mashup
 @RequestMapping
 public Map<String, Object> error(HttpServletRequest request) {
   RequestAttributes requestAttributes = new ServletRequestAttributes(request);
   return errorAttributes.getErrorAttributes(requestAttributes, showStacktrace);
 }