mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Chain caught InvalidEndpointRequestExceptions
Update `AbstractWebMvcEndpointHandlerMapping` to chain any caught InvalidEndpointRequestExceptions so that a more complete stacktrace is available. The exception has also been updated to a `ResponseStatusException` so that the reason can be propagated. Fixes gh-25642
This commit is contained in:
parent
ec21202d54
commit
130cc5b036
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -53,9 +53,9 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.handler.MatchableHandlerMapping;
|
||||
import org.springframework.web.servlet.handler.RequestMatchResult;
|
||||
@ -305,7 +305,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
|
||||
return handleResult(this.operation.invoke(invocationContext), HttpMethod.resolve(request.getMethod()));
|
||||
}
|
||||
catch (InvalidEndpointRequestException ex) {
|
||||
throw new BadOperationRequestException(ex.getReason());
|
||||
throw new InvalidEndpointBadRequestException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,11 +416,14 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
|
||||
|
||||
}
|
||||
|
||||
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
|
||||
private static class BadOperationRequestException extends RuntimeException {
|
||||
/**
|
||||
* Nested exception used to wrap a {@link InvalidEndpointRequestException} and provide
|
||||
* a {@link HttpStatus#BAD_REQUEST} status.
|
||||
*/
|
||||
private static class InvalidEndpointBadRequestException extends ResponseStatusException {
|
||||
|
||||
BadOperationRequestException(String message) {
|
||||
super(message);
|
||||
InvalidEndpointBadRequestException(InvalidEndpointRequestException cause) {
|
||||
super(HttpStatus.BAD_REQUEST, cause.getReason(), cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user