Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set detail from reason in both constructors of ResponseStatusException #29608

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
singhbaljit marked this conversation as resolved.
Show resolved Hide resolved

/**
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