Refine encoding/decoding exception handling
Starting with removing a package cycle on the use of ResponseStatusException in the codec package, this commit generally refines codec exception handling. The new [Encoding|Decoding]Exception mirror the existing HttpMessageNot[Readable|Writable]Exception and are used similarly especially to differentiate betwen 400 and 500 errors when parsing server request body content. The commit also aligns some of the exception handling of JSON and XML on the WebFlux side with that on the Spring MVC side. Issue: SPR-15516
This commit is contained in:
@@ -44,7 +44,6 @@ import org.springframework.web.reactive.result.method.annotation.ResponseBodyRes
|
||||
import org.springframework.web.server.NotAcceptableStatusException;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
@@ -52,8 +51,10 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
|
||||
/**
|
||||
* Test the effect of exceptions at different stages of request processing by
|
||||
@@ -98,7 +99,7 @@ public class DispatcherHandlerErrorTests {
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
.consumeErrorWith(error -> assertSame(EXCEPTION, error.getCause()))
|
||||
.consumeErrorWith(error -> assertSame(EXCEPTION, error))
|
||||
.verify();
|
||||
}
|
||||
|
||||
@@ -147,10 +148,7 @@ public class DispatcherHandlerErrorTests {
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(ServerWebInputException.class));
|
||||
assertSame(EXCEPTION, error.getCause());
|
||||
})
|
||||
.consumeErrorWith(error -> assertSame(EXCEPTION, error))
|
||||
.verify();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user