Skip to content

Commit

Permalink
ResponseStatusException delegates to protected constructor
Browse files Browse the repository at this point in the history
This ensures that by default the reason is used to set the "detail"
field. It's a follow-up fix to a27f2e9
which resolved the issue partially.

Closes gh-29608
  • Loading branch information
singhbaljit authored and rstoyanchev committed Dec 2, 2022
1 parent 955ca4d commit b1fdb14
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Expand Up @@ -56,7 +56,9 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
}
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);
}
}


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


Expand Down
Expand Up @@ -76,8 +76,7 @@ public ResponseStatusException(int rawStatusCode, @Nullable String reason, @Null
* @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);
}

/**
Expand Down
Expand Up @@ -111,22 +111,22 @@ public void notAnnotated() {
}

@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);
assertResolved(mav, 410, "gone.reason");
}

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

0 comments on commit b1fdb14

Please sign in to comment.