/** * Template method that handles an {@link ResponseStatusException}. * <p>The default implementation delegates to {@link #applyStatusAndReason} * with the status code and reason from the exception. * @param ex the exception * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen at the * time of the exception, e.g. if multipart resolution failed * @return an empty ModelAndView, i.e. exception resolved * @since 5.0 */ protected ModelAndView resolveResponseStatusException(ResponseStatusException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws Exception { int statusCode = ex.getStatus().value(); String reason = ex.getReason(); return applyStatusAndReason(statusCode, reason, response); }
private String determineMessage(Throwable error) { if (error instanceof WebExchangeBindException) { return error.getMessage(); } if (error instanceof ResponseStatusException) { return ((ResponseStatusException) error).getReason(); } ResponseStatus responseStatus = AnnotatedElementUtils .findMergedAnnotation(error.getClass(), ResponseStatus.class); if (responseStatus != null) { return responseStatus.reason(); } return error.getMessage(); }
/** * Template method that handles an {@link ResponseStatusException}. * <p>The default implementation delegates to {@link #applyStatusAndReason} * with the status code and reason from the exception. * @param ex the exception * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen at the * time of the exception, e.g. if multipart resolution failed * @return an empty ModelAndView, i.e. exception resolved * @since 5.0 */ protected ModelAndView resolveResponseStatusException(ResponseStatusException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws Exception { int statusCode = ex.getStatus().value(); String reason = ex.getReason(); return applyStatusAndReason(statusCode, reason, response); }