Skip to content

Commit 360f555

Browse files
dreis2211sbrannen
authored andcommittedMay 18, 2021
Introduce ResponseEntity.internalServerError()
Closes gh-26952
1 parent 7c75602 commit 360f555

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎spring-web/src/main/java/org/springframework/http/ResponseEntity.java

+10
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ public static BodyBuilder unprocessableEntity() {
317317
return status(HttpStatus.UNPROCESSABLE_ENTITY);
318318
}
319319

320+
/**
321+
* Create a builder with an
322+
* {@linkplain HttpStatus#INTERNAL_SERVER_ERROR INTERNAL_SERVER_ERROR} status.
323+
* @return the created builder
324+
* @since 5.3.8
325+
*/
326+
public static BodyBuilder internalServerError() {
327+
return status(HttpStatus.INTERNAL_SERVER_ERROR);
328+
}
329+
320330

321331
/**
322332
* Defines a builder that adds headers to the response entity.

‎spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -159,6 +159,15 @@ public void unprocessableEntity() throws URISyntaxException {
159159
assertThat(responseEntity.getBody()).isEqualTo("error");
160160
}
161161

162+
@Test
163+
public void internalServerError() throws URISyntaxException {
164+
ResponseEntity<String> responseEntity = ResponseEntity.internalServerError().body("error");
165+
166+
assertThat(responseEntity).isNotNull();
167+
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
168+
assertThat(responseEntity.getBody()).isEqualTo("error");
169+
}
170+
162171
@Test
163172
public void headers() throws URISyntaxException {
164173
URI location = new URI("location");

0 commit comments

Comments
 (0)