Java 类org.springframework.boot.autoconfigure.web.DefaultErrorAttributes 实例源码

项目:spring-boot-jpa    文件:BootJpaApplication.java   
/**
 * 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;
        }
    };
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebRequestTraceFilterTests.java   
@Test
public void filterHasError() {
    this.filter.setErrorAttributes(new DefaultErrorAttributes());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.setStatus(500);
    request.setAttribute("javax.servlet.error.exception",
            new IllegalStateException("Foo"));
    response.addHeader("Content-Type", "application/json");
    Map<String, Object> trace = this.filter.getTrace(request);
    this.filter.enhanceTrace(trace, response);
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) trace.get("error");
    System.err.println(map);
    assertThat(map.get("message").toString()).isEqualTo("Foo");
}
项目:spring-boot-concourse    文件:WebRequestTraceFilterTests.java   
@Test
public void filterHasError() {
    this.filter.setErrorAttributes(new DefaultErrorAttributes());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.setStatus(500);
    request.setAttribute("javax.servlet.error.exception",
            new IllegalStateException("Foo"));
    response.addHeader("Content-Type", "application/json");
    Map<String, Object> trace = this.filter.getTrace(request);
    this.filter.enhanceTrace(trace, response);
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) trace.get("error");
    System.err.println(map);
    assertThat(map.get("message").toString()).isEqualTo("Foo");
}
项目:contestparser    文件:WebRequestTraceFilterTests.java   
@Test
public void filterHasError() {
    this.filter.setErrorAttributes(new DefaultErrorAttributes());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.setStatus(500);
    request.setAttribute("javax.servlet.error.exception",
            new IllegalStateException("Foo"));
    response.addHeader("Content-Type", "application/json");
    Map<String, Object> trace = this.filter.getTrace(request);
    this.filter.enhanceTrace(trace, response);
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) trace.get("error");
    System.err.println(map);
    assertEquals("Foo", map.get("message").toString());
}
项目:searchbox-core    文件:SearchBoxConfiguration.java   
@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;
        }
    };

}
项目:xq_seckill_microservice    文件:ErrorController.java   
@Autowired
public ErrorController(ServerProperties serverProperties) {
    super(new DefaultErrorAttributes(), serverProperties.getError());
}
项目:mandrel    文件:RestConfiguration.java   
@Bean
@ConditionalOnMissingBean
public DefaultErrorAttributes errorAttributes() {
    return new DefaultErrorAttributes();
}
项目:mandrel    文件:WebConfiguration.java   
@Bean
@ConditionalOnMissingBean
public DefaultErrorAttributes errorAttributes() {
    return new DefaultErrorAttributes();
}