Add RFC-7807 response interception
Closes gh-31822
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.validation.DefaultMessageCodesResolver;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.web.ErrorResponse;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
@@ -198,8 +199,35 @@ public class DelegatingWebMvcConfigurationTests {
|
||||
(HandlerExceptionResolverComposite) webMvcConfig
|
||||
.handlerExceptionResolver(webMvcConfig.mvcContentNegotiationManager());
|
||||
|
||||
assertThat(composite.getExceptionResolvers())
|
||||
.as("Only one custom converter is expected").hasSize(1);
|
||||
assertThat(composite.getExceptionResolvers()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addErrorResponseInterceptors() {
|
||||
ErrorResponse.Interceptor interceptor = (detail, errorResponse) -> {};
|
||||
WebMvcConfigurer configurer = new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addErrorResponseInterceptors(List<ErrorResponse.Interceptor> interceptors) {
|
||||
interceptors.add(interceptor);
|
||||
}
|
||||
};
|
||||
webMvcConfig.setConfigurers(Collections.singletonList(configurer));
|
||||
|
||||
RequestMappingHandlerAdapter adapter = webMvcConfig.requestMappingHandlerAdapter(
|
||||
webMvcConfig.mvcContentNegotiationManager(),
|
||||
webMvcConfig.mvcConversionService(),
|
||||
webMvcConfig.getValidator());
|
||||
|
||||
assertThat(adapter.getErrorResponseInterceptors()).containsExactly(interceptor);
|
||||
|
||||
HandlerExceptionResolverComposite composite =
|
||||
(HandlerExceptionResolverComposite) webMvcConfig.handlerExceptionResolver(
|
||||
webMvcConfig.mvcContentNegotiationManager());
|
||||
|
||||
ExceptionHandlerExceptionResolver resolver =
|
||||
(ExceptionHandlerExceptionResolver) composite.getExceptionResolvers().get(0);
|
||||
|
||||
assertThat(resolver.getErrorResponseInterceptors()).containsExactly(interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user