Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 900f1ad

Browse files
committed
Added 404 Status to default error controller
1 parent 808b0eb commit 900f1ad

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/de/filefighter/rest/rest/RestErrorController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.springframework.boot.web.servlet.error.ErrorController;
44
import org.springframework.hateoas.EntityModel;
5+
import org.springframework.http.HttpStatus;
6+
import org.springframework.http.ResponseEntity;
57
import org.springframework.web.bind.annotation.RequestMapping;
68
import org.springframework.web.bind.annotation.RestController;
79
import springfox.documentation.annotations.ApiIgnore;
@@ -13,8 +15,8 @@ public class RestErrorController implements ErrorController {
1315
public static final String DEFAULT_ERROR_PATH = "/error";
1416

1517
@RequestMapping(value = DEFAULT_ERROR_PATH)
16-
public EntityModel<ServerResponse> error() {
17-
return new ServerResponse("denied", "This endpoint does not exist.").toModel();
18+
public ResponseEntity<ServerResponse> error() {
19+
return new ResponseEntity<>(new ServerResponse("denied", "This endpoint does not exist."), HttpStatus.NOT_FOUND);
1820
}
1921

2022
@Override

src/test/java/de/filefighter/rest/rest/RestErrorControllerUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void setUp() {
2727
@Test
2828
void errorHandleingDoesWork() throws Exception {
2929
mockMvc.perform(get(RestErrorController.DEFAULT_ERROR_PATH))
30-
.andExpect(status().isOk())
30+
.andExpect(status().is(404))
3131
.andReturn();
3232
}
3333

0 commit comments

Comments
 (0)