ResponseStatusException delegates to protected constructor
This ensures that by default the reason is used to set the "detail"
field. It's a follow-up fix to a27f2e994b
which resolved the issue partially.
Closes gh-29608
This commit is contained in:
parent
955ca4d146
commit
b1fdb148d0
|
@ -56,7 +56,9 @@ public class MethodNotAllowedException extends ResponseStatusException {
|
|||
}
|
||||
this.method = method;
|
||||
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
|
||||
setDetail(this.httpMethods.isEmpty() ? getReason() : "Supported methods: " + this.httpMethods);
|
||||
if (!this.httpMethods.isEmpty()) {
|
||||
setDetail("Supported methods: " + this.httpMethods);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ public class MissingRequestValueException extends ServerWebInputException {
|
|||
this.name = name;
|
||||
this.type = type;
|
||||
this.label = label;
|
||||
setDetail(getReason());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,8 +76,7 @@ public class ResponseStatusException extends ErrorResponseException {
|
|||
* @param cause a nested exception (optional)
|
||||
*/
|
||||
public ResponseStatusException(HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause) {
|
||||
super(status, cause);
|
||||
this.reason = reason;
|
||||
this(status, reason, cause, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ResponseStatusExceptionResolverTests {
|
|||
}
|
||||
|
||||
@Test // SPR-12903
|
||||
public void nestedException() throws Exception {
|
||||
public void nestedException() {
|
||||
Exception cause = new StatusCodeAndReasonMessageException();
|
||||
TypeMismatchException ex = new TypeMismatchException("value", ITestBean.class, cause);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
|
||||
|
@ -119,14 +119,14 @@ public class ResponseStatusExceptionResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void responseStatusException() throws Exception {
|
||||
public void responseStatusException() {
|
||||
ResponseStatusException ex = new ResponseStatusException(HttpStatus.BAD_REQUEST);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
|
||||
assertResolved(mav, 400, null);
|
||||
}
|
||||
|
||||
@Test // SPR-15524
|
||||
public void responseStatusExceptionWithReason() throws Exception {
|
||||
public void responseStatusExceptionWithReason() {
|
||||
ResponseStatusException ex = new ResponseStatusException(HttpStatus.BAD_REQUEST, "The reason");
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
|
||||
assertResolved(mav, 400, "The reason");
|
||||
|
|
Loading…
Reference in New Issue