diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java index 640fed7edac..8712b1c69b9 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java @@ -43,7 +43,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.result.condition.ParamsRequestCondition; -import org.springframework.web.server.BadRequestStatusException; +import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.MethodNotAllowedException; import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; @@ -203,7 +203,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe * and HTTP method but not by consumable media types * @throws NotAcceptableStatusException if there are matches by URL and HTTP * method but not by producible media types - * @throws BadRequestStatusException if there are matches by URL and HTTP + * @throws ServerWebInputException if there are matches by URL and HTTP * method but not by query parameter conditions */ @Override @@ -278,7 +278,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toArray(new String[entry.getValue().size()])) ); - throw new BadRequestStatusException("Unsatisfied query parameter conditions: " + + throw new ServerWebInputException("Unsatisfied query parameter conditions: " + paramConditions + ", actual parameters: " + params); } else { diff --git a/spring-web-reactive/src/main/java/org/springframework/web/server/BadRequestStatusException.java b/spring-web-reactive/src/main/java/org/springframework/web/server/ServerWebInputException.java similarity index 76% rename from spring-web-reactive/src/main/java/org/springframework/web/server/BadRequestStatusException.java rename to spring-web-reactive/src/main/java/org/springframework/web/server/ServerWebInputException.java index 5f469b0dd7e..26af9f6a95d 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/server/BadRequestStatusException.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/server/ServerWebInputException.java @@ -21,11 +21,13 @@ import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; /** - * Exception for errors that fit response status 400 (bad request). + * Exception for errors that fit response status 400 (bad request) for use in + * Spring Web applications. The exception provides additional fields (e.g. + * an optional {@link MethodParameter} if related to the error). * * @author Rossen Stoyanchev */ -public class BadRequestStatusException extends ResponseStatusException { +public class ServerWebInputException extends ResponseStatusException { private final MethodParameter parameter; @@ -33,21 +35,21 @@ public class BadRequestStatusException extends ResponseStatusException { /** * Constructor with an explanation only. */ - public BadRequestStatusException(String reason) { + public ServerWebInputException(String reason) { this(reason, null); } /** * Constructor for a 400 error linked to a specific {@code MethodParameter}. */ - public BadRequestStatusException(String reason, MethodParameter parameter) { + public ServerWebInputException(String reason, MethodParameter parameter) { this(reason, parameter, null); } /** * Constructor for a 400 error with a root cause. */ - public BadRequestStatusException(String reason, MethodParameter parameter, Throwable cause) { + public ServerWebInputException(String reason, MethodParameter parameter, Throwable cause) { super(HttpStatus.BAD_REQUEST, reason, cause); this.parameter = parameter; } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java index 2c26457328e..ada1c7a058a 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java @@ -50,7 +50,7 @@ import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.result.method.RequestMappingInfo.BuilderConfiguration; -import org.springframework.web.server.BadRequestStatusException; +import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.MethodNotAllowedException; import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; @@ -208,7 +208,7 @@ public class RequestMappingInfoHandlerMappingTests { public void getHandlerUnsatisfiedServletRequestParameterException() throws Exception { ServerWebExchange exchange = createExchange(HttpMethod.GET, "/params"); Mono mono = this.handlerMapping.getHandler(exchange); - assertError(mono, BadRequestStatusException.class, ex -> { + assertError(mono, ServerWebInputException.class, ex -> { assertEquals(ex.getReason(), "Unsatisfied query parameter conditions: " + "[[bar=baz], [foo=bar]], actual parameters: {}"); });