/** * Customized ErrorAttribute bean. * We really need to find a cleaner way of handling these error messages. * * @return customized ErrorAttributes */ @Bean public ErrorAttributes errorAttributes() { return new DefaultErrorAttributes() { @Override public Map<String, Object> getErrorAttributes( final RequestAttributes requestAttributes, final boolean includeStackTrace) { Map<String, Object> attributes = super .getErrorAttributes(requestAttributes, includeStackTrace); Throwable error = getError(requestAttributes); if (error instanceof MethodArgumentNotValidException) { MethodArgumentNotValidException ex = ((MethodArgumentNotValidException) error); attributes.put("errors", ex.getMessage()); } return attributes; } }; }
/** * 抄的是{@link ErrorMvcAutoConfiguration#basicErrorController(ErrorAttributes)} * * @param errorAttributes * @return */ @Bean public CustomErrorController customErrorController(ErrorAttributes errorAttributes) { return new CustomErrorController( errorAttributes, this.serverProperties.getError(), this.errorViewResolvers ); }
@Override public ErrorData getErrorData(BindException ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex.getBindingResult()) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .withThrowable(ex) .build(); }
@Override public ErrorData getErrorData(MethodArgumentNotValidException ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex.getBindingResult()) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .withThrowable(ex) .build(); }
@Override public ErrorData getErrorData(T ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); String requestHeaders = getRequestHeaders(requestAttributes); return buildErrorData(ex, requestHeaders) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .build(); }
@Override public ErrorData getErrorData(Throwable ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex, defaultResponseStatus) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .withResponseStatus(defaultResponseStatus) .build(); }
@Override public ErrorData getErrorData(T ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex, responseHttpStatus) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .build(); }
@Override public ErrorData getErrorData(ExternalHttpRequestException ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex, ex.getStatusCode()) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .build(); }
@Override public ErrorData getErrorData(ApplicationException ex, HttpServletRequest request, HttpStatus defaultResponseStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { String requestUri = getRequestUri(errorAttributes, requestAttributes); return buildErrorData(ex) .withRequestMethod(request.getMethod()) .withRequestUri(requestUri) .build(); }
public ServletFilterErrorHandler(ErrorAttributes errorAttributes, ServerProperties serverProperties, ErrorsFactory errorsFactory, ErrorDataProviderContext providerContext) { super(errorAttributes, emptyList()); this.errorAttributes = errorAttributes; errorProperties = serverProperties.getError(); this.errorsFactory = errorsFactory; this.providerContext = providerContext; }
public TraceWebFilterAutoConfiguration(TraceRepository traceRepository, TraceProperties traceProperties, ObjectProvider<ErrorAttributes> errorAttributesProvider) { this.traceRepository = traceRepository; this.traceProperties = traceProperties; this.errorAttributes = errorAttributesProvider.getIfAvailable(); }
@Bean public ErrorAttributes customizeErrorResponseAttributes() { return new DefaultErrorAttributes(){ @Override public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) { Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace); errorAttributes.remove("timestamp"); errorAttributes.remove("exception"); return errorAttributes; } }; }
@Bean @ConditionalOnBean(ErrorAttributes.class) public ManagementErrorEndpoint errorEndpoint(ServerProperties serverProperties, ErrorAttributes errorAttributes) { return new ManagementErrorEndpoint(serverProperties.getError().getPath(), errorAttributes); }
@Before public void before() { this.errorAttributes = mock(ErrorAttributes.class); Map<String, Object> result = new HashMap<>(); result.put("exception", "exception"); result.put("message", "message"); when(errorAttributes.getErrorAttributes(any(), anyBoolean())).thenReturn(result); this.subject = new ErrorController(errorAttributes); }
@Bean public ErrorAttributes errorAttributes() { // override boot's DefaultErrorAttributes return new SkipperErrorAttributes(); }
@Inject public ErrorResource(ErrorAttributes errorAttributes) { super(errorAttributes); this.errorAttributes = errorAttributes; }
public CustomErrorController(ErrorAttributes errorAttributes) { super(errorAttributes); }
public CrnkErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) { super(errorAttributes, errorProperties); }
public CrnkErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties, List<ErrorViewResolver> errorViewResolvers) { super(errorAttributes, errorProperties, errorViewResolvers); }
@Bean @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) public BasicErrorController jsonapiErrorController(ErrorAttributes errorAttributes) { return new CrnkErrorController(errorAttributes, this.serverProperties.getError(), this.errorViewResolvers); }
public ZuulErrorController(ErrorAttributes errorAttributes) { super(errorAttributes); }
public CustomErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) { super(errorAttributes, errorProperties); }
public CustomErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties, List<ErrorViewResolver> errorViewResolvers) { super(errorAttributes, errorProperties, errorViewResolvers); }
@Bean public ErrorAttributes errorAttributes() { return new CustomErrorAttributes(); }
/** * 初始化ExceptionController */ @Autowired public DemoErrorController(ErrorAttributes errorAttributes) { Assert.notNull(errorAttributes, "ErrorAttributes must not be null"); this.errorAttributes = errorAttributes; }
@Override public ErrorData getErrorData(MissingServletRequestParameterException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, BAD_REQUEST, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(ServletRequestBindingException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, BAD_REQUEST, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(NoHandlerFoundException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, NOT_FOUND, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(TypeMismatchException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, BAD_REQUEST, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(MissingServletRequestPartException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, BAD_REQUEST, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(HttpMediaTypeNotAcceptableException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, NOT_ACCEPTABLE, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(HttpMessageNotReadableException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, BAD_REQUEST, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, METHOD_NOT_ALLOWED, errorAttributes, requestAttributes); }
@Override public ErrorData getErrorData(HttpMediaTypeNotSupportedException ex, HttpServletRequest request, HttpStatus responseHttpStatus, ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return super.getErrorData(ex, request, UNSUPPORTED_MEDIA_TYPE, errorAttributes, requestAttributes); }
protected String getRequestUri(ErrorAttributes errorAttributes, RequestAttributes requestAttributes) { return errorAttributes.getErrorAttributes(requestAttributes, false).getOrDefault(REQUEST_URI_ERROR_ATTRIBUTE, NOT_AVAILABLE_DATA).toString(); }
@Bean @ConditionalOnMissingBean public ServletFilterErrorHandler servletFilterErrorHandler(ErrorAttributes errorAttributes, ErrorsFactory errorsFactory, ErrorDataProviderContext providerContext) { return new ServletFilterErrorHandler(errorAttributes, serverProperties, errorsFactory, providerContext); }
public QuartermasterErrorController(ErrorAttributes errorAttributes) { this.errorAttributes = errorAttributes; }
@Autowired public TowerIndexes(ErrorAttributes errorAttributes) { super(errorAttributes); }
/** * @param errorAttributes */ @Autowired public CustomErrorController(ErrorAttributes errorAttributes) { Assert.notNull(errorAttributes, "ErrorAttributes must not be null"); this.errorAttributes = errorAttributes; }