@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";
 }
  @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);
  }
 private Map<String, Object> getErrorAttributes(
     HttpServletRequest request, boolean includeStackTrace) {
   RequestAttributes requestAttributes = new ServletRequestAttributes(request);
   return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
 }
Example #4
0
 @RequestMapping
 public Map<String, Object> error(HttpServletRequest request) {
   RequestAttributes requestAttributes = new ServletRequestAttributes(request);
   return errorAttributes.getErrorAttributes(requestAttributes, showStacktrace);
 }