ErrorResponse support in Spring MVC exception hierarchy
All Spring MVC exceptions from spring-web, now implement ErrorResponse
and expose HTTP error response information, including an RFC 7807 body.
See gh-27052
getBody().setDetail("Could not parse Accept header");
}
/**
@ -42,7 +47,23 @@ public class HttpMediaTypeNotAcceptableException extends HttpMediaTypeException
@@ -42,7 +47,23 @@ public class HttpMediaTypeNotAcceptableException extends HttpMediaTypeException
@ -34,6 +39,9 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@@ -34,6 +39,9 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@Nullable
privatefinalMediaTypecontentType;
@Nullable
privatefinalHttpMethodhttpMethod;
/**
*CreateanewHttpMediaTypeNotSupportedException.
@ -42,6 +50,8 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@@ -42,6 +50,8 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
getBody().setDetail("Could not parse Content-Type");
}
/**
@ -50,21 +60,38 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@@ -50,21 +60,38 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
getBody().setDetail("Content-Type "+this.contentType+" is not supported");
}
@ -76,4 +103,22 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@@ -76,4 +103,22 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException {
@ -74,7 +80,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
@@ -74,7 +80,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
this(method,supportedMethods,"Request method '"+method+"' not supported");
this(method,supportedMethods,"Request method '"+method+"' is not supported");
}
/**
@ -87,6 +93,8 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
@@ -87,6 +93,8 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
.withDetail("Method '"+method+"' is not supported");
}
@ -123,4 +131,24 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
@@ -123,4 +131,24 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
@ -43,9 +48,20 @@ public class MethodArgumentNotValidException extends BindException {
@@ -43,9 +48,20 @@ public class MethodArgumentNotValidException extends BindException {
@ -55,9 +71,13 @@ public class MethodArgumentNotValidException extends BindException {
@@ -55,9 +71,13 @@ public class MethodArgumentNotValidException extends BindException {
@ -57,6 +57,7 @@ public class MissingMatrixVariableException extends MissingRequestValueException
@@ -57,6 +57,7 @@ public class MissingMatrixVariableException extends MissingRequestValueException
super("",missingAfterConversion);
this.variableName=variableName;
this.parameter=parameter;
getBody().setDetail("Required path parameter '"+this.variableName+"' is not present");
@ -59,6 +60,7 @@ public class MissingPathVariableException extends MissingRequestValueException {
@@ -59,6 +60,7 @@ public class MissingPathVariableException extends MissingRequestValueException {
super("",missingAfterConversion);
this.variableName=variableName;
this.parameter=parameter;
getBody().setDetail("Required URI variable '"+this.variableName+"' is not present");
}
@ -83,4 +85,10 @@ public class MissingPathVariableException extends MissingRequestValueException {
@@ -83,4 +85,10 @@ public class MissingPathVariableException extends MissingRequestValueException {
@ -57,6 +57,7 @@ public class MissingRequestCookieException extends MissingRequestValueException
@@ -57,6 +57,7 @@ public class MissingRequestCookieException extends MissingRequestValueException
super("",missingAfterConversion);
this.cookieName=cookieName;
this.parameter=parameter;
getBody().setDetail("Required cookie '"+this.cookieName+"' is not present");
@ -57,6 +57,7 @@ public class MissingRequestHeaderException extends MissingRequestValueException
@@ -57,6 +57,7 @@ public class MissingRequestHeaderException extends MissingRequestValueException
super("",missingAfterConversion);
this.headerName=headerName;
this.parameter=parameter;
getBody().setDetail("Required header '"+this.headerName+"' is not present");
@ -52,6 +52,7 @@ public class MissingServletRequestParameterException extends MissingRequestValue
@@ -52,6 +52,7 @@ public class MissingServletRequestParameterException extends MissingRequestValue
super("",missingAfterConversion);
this.parameterName=parameterName;
this.parameterType=parameterType;
getBody().setDetail("Required parameter '"+this.parameterName+"' is not present");
@ -49,4 +55,15 @@ public class ServletRequestBindingException extends NestedServletException {
@@ -49,4 +55,15 @@ public class ServletRequestBindingException extends NestedServletException {
@ -42,6 +42,7 @@ public class MissingServletRequestPartException extends ServletRequestBindingExc
@@ -42,6 +42,7 @@ public class MissingServletRequestPartException extends ServletRequestBindingExc
@ -156,7 +156,7 @@ public class DispatcherHandler implements WebHandler, PreFlightRequestHandler, A
@@ -156,7 +156,7 @@ public class DispatcherHandler implements WebHandler, PreFlightRequestHandler, A
@ -200,8 +200,8 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@@ -200,8 +200,8 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@ -42,6 +45,8 @@ public class NoHandlerFoundException extends ServletException {
@@ -42,6 +45,8 @@ public class NoHandlerFoundException extends ServletException {
@ -57,6 +62,11 @@ public class NoHandlerFoundException extends ServletException {
@@ -57,6 +62,11 @@ public class NoHandlerFoundException extends ServletException {
}
@Override
publicintgetRawStatusCode(){
returnHttpStatus.NOT_FOUND.value();
}
publicStringgetHttpMethod(){
returnthis.httpMethod;
}
@ -69,4 +79,9 @@ public class NoHandlerFoundException extends ServletException {
@@ -69,4 +79,9 @@ public class NoHandlerFoundException extends ServletException {
@ -264,7 +264,8 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@@ -264,7 +264,8 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
@ -206,7 +206,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
@@ -206,7 +206,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements