Search in sources :

Example 1 with WebExceptionHandler

use of org.springframework.web.server.WebExceptionHandler in project spring-framework by spring-projects.

the class ExceptionHandlingHttpHandlerTests method unresolvedException.

@Test
public void unresolvedException() throws Exception {
    WebExceptionHandler exceptionHandler = new UnresolvedExceptionHandler();
    createWebHandler(exceptionHandler).handle(this.exchange).block();
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.exchange.getResponse().getStatusCode());
}
Also used : WebExceptionHandler(org.springframework.web.server.WebExceptionHandler) Test(org.junit.Test)

Example 2 with WebExceptionHandler

use of org.springframework.web.server.WebExceptionHandler in project spring-framework by spring-projects.

the class ExceptionHandlingHttpHandlerTests method handleErrorSignal.

@Test
public void handleErrorSignal() throws Exception {
    WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
    createWebHandler(exceptionHandler).handle(this.exchange).block();
    assertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode());
}
Also used : WebExceptionHandler(org.springframework.web.server.WebExceptionHandler) Test(org.junit.Test)

Example 3 with WebExceptionHandler

use of org.springframework.web.server.WebExceptionHandler in project spring-framework by spring-projects.

the class ExceptionHandlingHttpHandlerTests method thrownExceptionBecomesErrorSignal.

@Test
public void thrownExceptionBecomesErrorSignal() throws Exception {
    WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
    createWebHandler(exceptionHandler).handle(this.exchange).block();
    assertEquals(HttpStatus.BAD_REQUEST, this.exchange.getResponse().getStatusCode());
}
Also used : WebExceptionHandler(org.springframework.web.server.WebExceptionHandler) Test(org.junit.Test)

Example 4 with WebExceptionHandler

use of org.springframework.web.server.WebExceptionHandler in project spring-framework by spring-projects.

the class DispatcherHandlerErrorTests method webExceptionHandler.

@Test
public void webExceptionHandler() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/unknown-argument-type").toExchange();
    List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
    WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers);
    webHandler.handle(exchange).block(Duration.ofSeconds(5));
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exchange.getResponse().getStatusCode());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) ExceptionHandlingWebHandler(org.springframework.web.server.handler.ExceptionHandlingWebHandler) WebExceptionHandler(org.springframework.web.server.WebExceptionHandler) WebHandler(org.springframework.web.server.WebHandler) ExceptionHandlingWebHandler(org.springframework.web.server.handler.ExceptionHandlingWebHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 WebExceptionHandler (org.springframework.web.server.WebExceptionHandler)4 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1 WebHandler (org.springframework.web.server.WebHandler)1 ExceptionHandlingWebHandler (org.springframework.web.server.handler.ExceptionHandlingWebHandler)1