提交 dd607d3e 编写于 作者: R Rossen Stoyanchev

BadRequestStatusException -> ServerWebInputException

The renaming makes it clear this exception is for use where 400 error
applies within a Spring web application where the error may be
associated with a MethodParameter, a BindingResult, and so on.

There is no need for BadRequestStatusException which can be expressed
with ResponseStatusException(HttpStatus.BAD_REQUEST, "reason").
上级 54eeb2cd
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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<Object> 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: {}");
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册