|
32 | 32 | import org.springframework.core.MethodParameter;
|
33 | 33 | import org.springframework.http.HttpHeaders;
|
34 | 34 | import org.springframework.http.HttpMethod;
|
35 |
| -import org.springframework.http.HttpStatus; |
36 | 35 | import org.springframework.http.HttpStatusCode;
|
37 | 36 | import org.springframework.http.MediaType;
|
38 | 37 | import org.springframework.http.ProblemDetail;
|
@@ -267,6 +266,15 @@ public void asyncRequestTimeoutException() {
|
267 | 266 | testException(new AsyncRequestTimeoutException());
|
268 | 267 | }
|
269 | 268 |
|
| 269 | + @Test // gh-14287, gh-31541 |
| 270 | + void serverErrorWithoutBody() { |
| 271 | + HttpStatusCode code = HttpStatusCode.valueOf(500); |
| 272 | + Exception ex = new IllegalStateException("internal error"); |
| 273 | + this.exceptionHandler.handleExceptionInternal(ex, null, new HttpHeaders(), code, this.request); |
| 274 | + |
| 275 | + assertThat(this.servletRequest.getAttribute("jakarta.servlet.error.exception")).isSameAs(ex); |
| 276 | + } |
| 277 | + |
270 | 278 | @Test
|
271 | 279 | public void controllerAdvice() throws Exception {
|
272 | 280 | StaticWebApplicationContext ctx = new StaticWebApplicationContext();
|
@@ -343,11 +351,6 @@ private ResponseEntity<Object> testException(Exception ex) {
|
343 | 351 | try {
|
344 | 352 | ResponseEntity<Object> entity = this.exceptionHandler.handleException(ex, this.request);
|
345 | 353 |
|
346 |
| - // SPR-9653 |
347 |
| - if (HttpStatus.INTERNAL_SERVER_ERROR.equals(entity.getStatusCode())) { |
348 |
| - assertThat(this.servletRequest.getAttribute("jakarta.servlet.error.exception")).isSameAs(ex); |
349 |
| - } |
350 |
| - |
351 | 354 | // Verify DefaultHandlerExceptionResolver would set the same status
|
352 | 355 | this.exceptionResolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
|
353 | 356 | assertThat(entity.getStatusCode().value()).isEqualTo(this.servletResponse.getStatus());
|
|
0 commit comments