Skip to content

Commit

Permalink
ResponseStatusException sets detail from reason again
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Nov 24, 2022
1 parent 284cf3e commit a27f2e9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
Expand Up @@ -56,8 +56,7 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
}
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);
}


Expand Down
Expand Up @@ -42,7 +42,7 @@ public MissingRequestValueException(String name, Class<?> type, String label, Me
this.name = name;
this.type = type;
this.label = label;
getBody().setDetail(getReason());
setDetail(getReason());
}


Expand Down
Expand Up @@ -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.");
}

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

this.supportedMediaTypes = Collections.unmodifiableList(mediaTypes);
getBody().setDetail("Acceptable representations: " + mediaTypes + ".");
setDetail("Acceptable representations: " + mediaTypes + ".");
}


Expand Down
Expand Up @@ -23,8 +23,9 @@
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
Expand Down Expand Up @@ -93,6 +94,7 @@ protected ResponseStatusException(

super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments);
this.reason = reason;
setDetail(reason);
}


Expand Down
Expand Up @@ -40,7 +40,7 @@ public UnsatisfiedRequestParameterException(List<String> conditions, MultiValueM
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) {
Expand Down
Expand Up @@ -62,7 +62,7 @@ public UnsupportedMediaTypeStatusException(@Nullable String reason) {
this.supportedMediaTypes = Collections.emptyList();
this.bodyType = null;
this.method = null;
getBody().setDetail("Could not parse Content-Type.");
setDetail("Could not parse Content-Type.");
}

/**
Expand Down
Expand Up @@ -316,7 +316,7 @@ void serverErrorException() {
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();
Expand Down

0 comments on commit a27f2e9

Please sign in to comment.