Skip to content

Commit 01880cd

Browse files
authored
Merge pull request #38 from bnc-projects/error_handler
Refactor error controller to return the actual status
2 parents 0096956 + a2701b7 commit 01880cd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
include:
2929
- stage: test
3030
- stage: deploy to development
31+
if: env(DEV_ACCOUNT_ID) is present
3132
jdk: openjdk8
3233
env:
3334
- CLUSTER_NAME=
@@ -44,6 +45,7 @@ jobs:
4445
on:
4546
branch: master
4647
- stage: deploy to production
48+
if: env(PROD_ACCOUNT_ID) is present
4749
jdk: openjdk8
4850
env:
4951
- CLUSTER_NAME=

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)