Commit 130cc5b0 authored by Phillip Webb's avatar Phillip Webb

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
parent ec21202d
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -53,9 +53,9 @@ import org.springframework.util.StringUtils; ...@@ -53,9 +53,9 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.MatchableHandlerMapping; import org.springframework.web.servlet.handler.MatchableHandlerMapping;
import org.springframework.web.servlet.handler.RequestMatchResult; import org.springframework.web.servlet.handler.RequestMatchResult;
...@@ -305,7 +305,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin ...@@ -305,7 +305,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
return handleResult(this.operation.invoke(invocationContext), HttpMethod.resolve(request.getMethod())); return handleResult(this.operation.invoke(invocationContext), HttpMethod.resolve(request.getMethod()));
} }
catch (InvalidEndpointRequestException ex) { catch (InvalidEndpointRequestException ex) {
throw new BadOperationRequestException(ex.getReason()); throw new InvalidEndpointBadRequestException(ex);
} }
} }
...@@ -416,11 +416,14 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin ...@@ -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) { InvalidEndpointBadRequestException(InvalidEndpointRequestException cause) {
super(message); super(HttpStatus.BAD_REQUEST, cause.getReason(), cause);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment