/** * Logs the exception; on ERROR level when status is 5xx, otherwise on INFO level without stack * trace, or DEBUG level with stack trace. The logger name is {@code ExceptionResolver}. * * @param requestAttributes requestAttributes * @param throwable throwable * @param resolvedError The exception to log. */ protected void logError( // final RequestAttributes requestAttributes, // final T throwable, // final ResolvedError resolvedError // ) { if (resolvedError.getStatus() >= HttpStatus.INTERNAL_SERVER_ERROR.value()) { final Marker marker = MarkerFactory.getMarker("error"); final String msg = String.format( // "%s ~> %d", // resolvedError.getPath(), // resolvedError.getStatus() // ); if (log.isTraceEnabled()) { log.trace("attributes in request scope: {}", // newArrayList(requestAttributes.getAttributeNames(SCOPE_REQUEST))); } log.warn(marker, msg, new Object[]{throwable}); } }
/** * Logs the exception; on ERROR level when status is 5xx, otherwise on INFO level without stack * trace, or DEBUG level with stack trace. The logger name is {@code ExceptionResolver}. * * @param requestAttributes requestAttributes * @param throwable throwable * @param resolvedError The exception to log. */ protected void logError( // final RequestAttributes requestAttributes, // final T throwable, // final ResolvedError resolvedError // ) { if (resolvedError.getStatus() >= HttpStatus.INTERNAL_SERVER_ERROR.value()) { final Marker marker = MarkerFactory.getMarker("error"); final String msg = String.format( // "%s ~> %d", // resolvedError.getPath(), // resolvedError.getStatus() // ); if (log.isTraceEnabled()) { log.trace("attributes in request scope: {}", // newArrayList(requestAttributes.getAttributeNames(SCOPE_REQUEST))); } log.warn(marker, msg, new Object[]{throwable}); } }
static ResponseEntity<ResolvedError> toResponseEntity(final ResolvedError error) { ResponseEntity<ResolvedError> entity = null; try { entity = new ResponseEntity<>( // error, // HttpHeader.toHttpHeaders(error.getHeaders()), // HttpStatus.valueOf(error.getStatus()) // ); } catch (final Exception ex) { if (log.isWarnEnabled()) { log.warn("Failed to process resolvedError: {}", error, ex); } } return entity; }
static ResponseEntity<ResolvedError> toResponseEntity(final ResolvedError error) { ResponseEntity<ResolvedError> entity = null; try { entity = new ResponseEntity<>( // error, // HttpHeader.toHttpHeaders(error.getHeaders()), // HttpStatus.valueOf(error.getStatus()) // ); } catch (final Exception ex) { if (log.isWarnEnabled()) { log.warn("Failed to process resolvedError: {}", error, ex); } } return entity; }
protected ModelAndView errorHtml( // final HttpServletRequest request, // final HttpServletResponse response // ) { final Map<String, Object> errorAttributes = getErrorAttributes( // request, // isIncludeStackTrace(request, MediaType.TEXT_HTML) // ); final ResolvedError resolvedError = ResolvedError.fromErrorAttributes(errorAttributes); final Integer status = resolvedError.getStatus();// this.getStatus(request) response.setStatus(status); // goto WhitelabelErrorViewConfiguration.defaultErrorView if not provided. final ModelAndView mav = new ModelAndView("error", resolvedError.toErrorAttributes()); mav.addObject(ResolvedError.RESOLVED_ERROR_OBJECT, resolvedError); return mav; }
protected ModelAndView errorHtml( // final HttpServletRequest request, // final HttpServletResponse response // ) { final Map<String, Object> errorAttributes = getErrorAttributes( // request, // isIncludeStackTrace(request, MediaType.TEXT_HTML) // ); final ResolvedError resolvedError = ResolvedError.fromErrorAttributes(errorAttributes); final Integer status = resolvedError.getStatus();// this.getStatus(request) response.setStatus(status); // goto WhitelabelErrorViewConfiguration.defaultErrorView if not provided. final ModelAndView mav = new ModelAndView("error", resolvedError.toErrorAttributes()); mav.addObject(ResolvedError.RESOLVED_ERROR_OBJECT, resolvedError); return mav; }