use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method responseIsCommittedWhenRequestIsAsyncAndExceptionIsThrown.
@Test
void responseIsCommittedWhenRequestIsAsyncAndExceptionIsThrown() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.request.setAsyncStarted(true);
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new RuntimeException("BAD");
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()).isEqualTo(this.response);
assertThat(this.response.isCommitted()).isTrue();
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method exceptionErrorWithCommittedResponse.
@Test
void exceptionErrorWithCommittedResponse() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
response.flushBuffer();
throw new RuntimeException("BAD");
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getForwardedUrl()).isNull();
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch.
@Test
void responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
setUpAsyncDispatch();
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
response.sendError(400, "BAD");
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()).isEqualTo(this.response);
assertThat(this.response.isCommitted()).isTrue();
}
use of org.springframework.boot.web.server.ErrorPage in project spring-boot by spring-projects.
the class ErrorPageFilterTests method globalError.
@Test
void globalError() throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new TestFilterChain((request, response, chain) -> response.sendError(400, "BAD"));
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(400);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).isEqualTo(400);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE)).isEqualTo("BAD");
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path");
assertThat(this.response.isCommitted()).isTrue();
assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
Aggregations