ResponseStatusException sets detail from reason again
Closes gh-29567
This commit is contained in:
@@ -56,8 +56,7 @@ public class MethodNotAllowedException extends ResponseStatusException {
|
|||||||
}
|
}
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
|
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
|
||||||
getBody().setDetail(this.httpMethods.isEmpty() ?
|
setDetail(this.httpMethods.isEmpty() ? getReason() : "Supported methods: " + this.httpMethods);
|
||||||
getReason() : "Supported methods: " + this.httpMethods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class MissingRequestValueException extends ServerWebInputException {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
getBody().setDetail(getReason());
|
setDetail(getReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class NotAcceptableStatusException extends ResponseStatusException {
|
|||||||
public NotAcceptableStatusException(String reason) {
|
public NotAcceptableStatusException(String reason) {
|
||||||
super(HttpStatus.NOT_ACCEPTABLE, reason, null, PARSE_ERROR_DETAIL_CODE, null);
|
super(HttpStatus.NOT_ACCEPTABLE, reason, null, PARSE_ERROR_DETAIL_CODE, null);
|
||||||
this.supportedMediaTypes = Collections.emptyList();
|
this.supportedMediaTypes = Collections.emptyList();
|
||||||
getBody().setDetail("Could not parse Accept header.");
|
setDetail("Could not parse Accept header.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +58,7 @@ public class NotAcceptableStatusException extends ResponseStatusException {
|
|||||||
"Could not find acceptable representation", null, null, new Object[] {mediaTypes});
|
"Could not find acceptable representation", null, null, new Object[] {mediaTypes});
|
||||||
|
|
||||||
this.supportedMediaTypes = Collections.unmodifiableList(mediaTypes);
|
this.supportedMediaTypes = Collections.unmodifiableList(mediaTypes);
|
||||||
getBody().setDetail("Acceptable representations: " + mediaTypes + ".");
|
setDetail("Acceptable representations: " + mediaTypes + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ import org.springframework.lang.Nullable;
|
|||||||
import org.springframework.web.ErrorResponseException;
|
import org.springframework.web.ErrorResponseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclass of {@link ErrorResponseException} that accepts a "reason" and maps
|
* Subclass of {@link ErrorResponseException} that accepts a "reason", and by
|
||||||
* it to the "detail" property of {@link org.springframework.http.ProblemDetail}.
|
* default maps that to the {@link ErrorResponseException#setDetail(String) "detail"}
|
||||||
|
* of the {@code ProblemDetail}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
@@ -93,6 +94,7 @@ public class ResponseStatusException extends ErrorResponseException {
|
|||||||
|
|
||||||
super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments);
|
super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
|
setDetail(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class UnsatisfiedRequestParameterException extends ServerWebInputExceptio
|
|||||||
super(initReason(conditions, params), null, null, null, new Object[] {conditions});
|
super(initReason(conditions, params), null, null, null, new Object[] {conditions});
|
||||||
this.conditions = conditions;
|
this.conditions = conditions;
|
||||||
this.requestParams = params;
|
this.requestParams = params;
|
||||||
getBody().setDetail("Invalid request parameters.");
|
setDetail("Invalid request parameters.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String initReason(List<String> conditions, MultiValueMap<String, String> queryParams) {
|
private static String initReason(List<String> conditions, MultiValueMap<String, String> queryParams) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException
|
|||||||
this.supportedMediaTypes = Collections.emptyList();
|
this.supportedMediaTypes = Collections.emptyList();
|
||||||
this.bodyType = null;
|
this.bodyType = null;
|
||||||
this.method = null;
|
this.method = null;
|
||||||
getBody().setDetail("Could not parse Content-Type.");
|
setDetail("Could not parse Content-Type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ public class ErrorResponseExceptionTests {
|
|||||||
ServerErrorException ex = new ServerErrorException("Failure", null);
|
ServerErrorException ex = new ServerErrorException("Failure", null);
|
||||||
|
|
||||||
assertStatus(ex, HttpStatus.INTERNAL_SERVER_ERROR);
|
assertStatus(ex, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
assertDetail(ex, null);
|
assertDetail(ex, "Failure");
|
||||||
assertDetailMessageCode(ex, null, new Object[] {ex.getReason()});
|
assertDetailMessageCode(ex, null, new Object[] {ex.getReason()});
|
||||||
|
|
||||||
assertThat(ex.getHeaders()).isEmpty();
|
assertThat(ex.getHeaders()).isEmpty();
|
||||||
|
|||||||
Reference in New Issue
Block a user