ResponseStatusException sets detail from reason again

Closes gh-29567
This commit is contained in:
rstoyanchev 2022-11-24 12:40:25 +00:00
parent 284cf3ecf2
commit a27f2e994b
7 changed files with 11 additions and 10 deletions

View File

@ -56,8 +56,7 @@ public class MethodNotAllowedException extends ResponseStatusException {
}
this.method = method;
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
getBody().setDetail(this.httpMethods.isEmpty() ?
getReason() : "Supported methods: " + this.httpMethods);
setDetail(this.httpMethods.isEmpty() ? getReason() : "Supported methods: " + this.httpMethods);
}

View File

@ -42,7 +42,7 @@ public class MissingRequestValueException extends ServerWebInputException {
this.name = name;
this.type = type;
this.label = label;
getBody().setDetail(getReason());
setDetail(getReason());
}

View File

@ -47,7 +47,7 @@ public class NotAcceptableStatusException extends ResponseStatusException {
public NotAcceptableStatusException(String reason) {
super(HttpStatus.NOT_ACCEPTABLE, reason, null, PARSE_ERROR_DETAIL_CODE, null);
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});
this.supportedMediaTypes = Collections.unmodifiableList(mediaTypes);
getBody().setDetail("Acceptable representations: " + mediaTypes + ".");
setDetail("Acceptable representations: " + mediaTypes + ".");
}

View File

@ -23,8 +23,9 @@ import org.springframework.lang.Nullable;
import org.springframework.web.ErrorResponseException;
/**
* Subclass of {@link ErrorResponseException} that accepts a "reason" and maps
* it to the "detail" property of {@link org.springframework.http.ProblemDetail}.
* Subclass of {@link ErrorResponseException} that accepts a "reason", and by
* default maps that to the {@link ErrorResponseException#setDetail(String) "detail"}
* of the {@code ProblemDetail}.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
@ -93,6 +94,7 @@ public class ResponseStatusException extends ErrorResponseException {
super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments);
this.reason = reason;
setDetail(reason);
}

View File

@ -40,7 +40,7 @@ public class UnsatisfiedRequestParameterException extends ServerWebInputExceptio
super(initReason(conditions, params), null, null, null, new Object[] {conditions});
this.conditions = conditions;
this.requestParams = params;
getBody().setDetail("Invalid request parameters.");
setDetail("Invalid request parameters.");
}
private static String initReason(List<String> conditions, MultiValueMap<String, String> queryParams) {

View File

@ -62,7 +62,7 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException
this.supportedMediaTypes = Collections.emptyList();
this.bodyType = null;
this.method = null;
getBody().setDetail("Could not parse Content-Type.");
setDetail("Could not parse Content-Type.");
}
/**

View File

@ -316,7 +316,7 @@ public class ErrorResponseExceptionTests {
ServerErrorException ex = new ServerErrorException("Failure", null);
assertStatus(ex, HttpStatus.INTERNAL_SERVER_ERROR);
assertDetail(ex, null);
assertDetail(ex, "Failure");
assertDetailMessageCode(ex, null, new Object[] {ex.getReason()});
assertThat(ex.getHeaders()).isEmpty();