Skip to content

Commit e32ae4d

Browse files
committed
Error controller should return the status based on the response status
1 parent 0096956 commit e32ae4d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/com/bnc/sbjb/rest/DefaultErrorController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.bnc.sbjb.rest;
22

3+
import com.bnc.sbjb.model.api.CustomError;
4+
import javax.servlet.http.HttpServletResponse;
35
import org.springframework.boot.web.servlet.error.ErrorController;
46
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
58
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.ResponseStatus;
79
import org.springframework.web.bind.annotation.RestController;
810

911
@RestController
1012
public class DefaultErrorController implements ErrorController {
1113

1214
private static final String PATH = "/error";
1315

14-
@ResponseStatus(HttpStatus.NOT_FOUND)
1516
@RequestMapping(value = PATH)
16-
public void error() {
17-
// Blank method since we don't need to do anything to handle unknown paths.
18-
// Any forked service may choose to handle some requests differently.
17+
public ResponseEntity<CustomError> error(HttpServletResponse response) {
18+
HttpStatus status = HttpStatus.valueOf(response.getStatus());
19+
return ResponseEntity.status(response.getStatus()).body(new CustomError(status, status.getReasonPhrase()));
1920
}
2021

2122
@Override

0 commit comments

Comments
 (0)