Skip to content

Commit a27f2e9

Browse files
committed
ResponseStatusException sets detail from reason again
Closes gh-29567
1 parent 284cf3e commit a27f2e9

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
5656
}
5757
this.method = method;
5858
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
59-
getBody().setDetail(this.httpMethods.isEmpty() ?
60-
getReason() : "Supported methods: " + this.httpMethods);
59+
setDetail(this.httpMethods.isEmpty() ? getReason() : "Supported methods: " + this.httpMethods);
6160
}
6261

6362

spring-web/src/main/java/org/springframework/web/server/MissingRequestValueException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public MissingRequestValueException(String name, Class<?> type, String label, Me
4242
this.name = name;
4343
this.type = type;
4444
this.label = label;
45-
getBody().setDetail(getReason());
45+
setDetail(getReason());
4646
}
4747

4848

spring-web/src/main/java/org/springframework/web/server/NotAcceptableStatusException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class NotAcceptableStatusException extends ResponseStatusException {
4747
public NotAcceptableStatusException(String reason) {
4848
super(HttpStatus.NOT_ACCEPTABLE, reason, null, PARSE_ERROR_DETAIL_CODE, null);
4949
this.supportedMediaTypes = Collections.emptyList();
50-
getBody().setDetail("Could not parse Accept header.");
50+
setDetail("Could not parse Accept header.");
5151
}
5252

5353
/**
@@ -58,7 +58,7 @@ public NotAcceptableStatusException(List<MediaType> mediaTypes) {
5858
"Could not find acceptable representation", null, null, new Object[] {mediaTypes});
5959

6060
this.supportedMediaTypes = Collections.unmodifiableList(mediaTypes);
61-
getBody().setDetail("Acceptable representations: " + mediaTypes + ".");
61+
setDetail("Acceptable representations: " + mediaTypes + ".");
6262
}
6363

6464

spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
import org.springframework.web.ErrorResponseException;
2424

2525
/**
26-
* Subclass of {@link ErrorResponseException} that accepts a "reason" and maps
27-
* it to the "detail" property of {@link org.springframework.http.ProblemDetail}.
26+
* Subclass of {@link ErrorResponseException} that accepts a "reason", and by
27+
* default maps that to the {@link ErrorResponseException#setDetail(String) "detail"}
28+
* of the {@code ProblemDetail}.
2829
*
2930
* @author Rossen Stoyanchev
3031
* @author Juergen Hoeller
@@ -93,6 +94,7 @@ protected ResponseStatusException(
9394

9495
super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments);
9596
this.reason = reason;
97+
setDetail(reason);
9698
}
9799

98100

spring-web/src/main/java/org/springframework/web/server/UnsatisfiedRequestParameterException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public UnsatisfiedRequestParameterException(List<String> conditions, MultiValueM
4040
super(initReason(conditions, params), null, null, null, new Object[] {conditions});
4141
this.conditions = conditions;
4242
this.requestParams = params;
43-
getBody().setDetail("Invalid request parameters.");
43+
setDetail("Invalid request parameters.");
4444
}
4545

4646
private static String initReason(List<String> conditions, MultiValueMap<String, String> queryParams) {

spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public UnsupportedMediaTypeStatusException(@Nullable String reason) {
6262
this.supportedMediaTypes = Collections.emptyList();
6363
this.bodyType = null;
6464
this.method = null;
65-
getBody().setDetail("Could not parse Content-Type.");
65+
setDetail("Could not parse Content-Type.");
6666
}
6767

6868
/**

spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void serverErrorException() {
316316
ServerErrorException ex = new ServerErrorException("Failure", null);
317317

318318
assertStatus(ex, HttpStatus.INTERNAL_SERVER_ERROR);
319-
assertDetail(ex, null);
319+
assertDetail(ex, "Failure");
320320
assertDetailMessageCode(ex, null, new Object[] {ex.getReason()});
321321

322322
assertThat(ex.getHeaders()).isEmpty();

0 commit comments

Comments
 (0)