Skip to content

Commit 4e7320f

Browse files
committed
발생한 예외 메시지 추가
1 parent 7c928a9 commit 4e7320f

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/main/java/com/zkdlu/apiresponsespringbootstarter/core/advice/ExceptionAdvice.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ private ExceptionProperties getExceptionProperties(Exception e, ExceptionPropert
4444
.filter(r -> r.getType().equals(e.getClass()))
4545
.findFirst()
4646
.orElse(unhandled);
47+
48+
exceptionModel.setMsg(exceptionModel.getMsg() + ": " + e.getMessage());
4749
return exceptionModel;
4850
}
4951

src/test/java/com/zkdlu/apiresponsespringbootstarter/DemoApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Demo demo2(@RequestParam String param) {
2525

2626
@GetMapping("exception")
2727
public Demo demo2() {
28-
throw new RuntimeException();
28+
throw new RuntimeException("메시지");
2929
}
3030

3131
static class Demo {

src/test/java/com/zkdlu/apiresponsespringbootstarter/HandlerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void setUp() {
6767
.andExpect(status().isBadRequest())
6868
.andExpect(jsonPath("$.success", equalTo(false)))
6969
.andExpect(jsonPath("$.code", equalTo(400)))
70-
.andExpect(jsonPath("$.msg", equalTo("Custom Message")))
70+
.andExpect(jsonPath("$.msg", equalTo("Custom Message: 메시지")))
7171
.andExpect(jsonPath("$.data", equalTo(null)))
7272
;
7373
}
@@ -79,7 +79,7 @@ void setUp() {
7979
.andExpect(status().isNotFound())
8080
.andExpect(jsonPath("$.success", equalTo(false)))
8181
.andExpect(jsonPath("$.code", equalTo(404)))
82-
.andExpect(jsonPath("$.msg", equalTo("Not Found")))
82+
.andExpect(jsonPath("$.msg", equalTo("Not Found: No handler found for GET /asdf")))
8383
.andExpect(jsonPath("$.data", equalTo(null)))
8484
;
8585
}
@@ -91,7 +91,7 @@ void setUp() {
9191
.andExpect(status().isBadRequest())
9292
.andExpect(jsonPath("$.success", equalTo(false)))
9393
.andExpect(jsonPath("$.code", equalTo(400)))
94-
.andExpect(jsonPath("$.msg", equalTo("Bad Request")))
94+
.andExpect(jsonPath("$.msg", equalTo("Bad Request: Required String parameter 'param' is not present")))
9595
.andExpect(jsonPath("$.data", equalTo(null)))
9696
;
9797
}
@@ -103,7 +103,7 @@ void setUp() {
103103
.andExpect(status().isMethodNotAllowed())
104104
.andExpect(jsonPath("$.success", equalTo(false)))
105105
.andExpect(jsonPath("$.code", equalTo(405)))
106-
.andExpect(jsonPath("$.msg", equalTo("Method Not Allowed")))
106+
.andExpect(jsonPath("$.msg", equalTo("Method Not Allowed: Request method 'POST' not supported")))
107107
.andExpect(jsonPath("$.data", equalTo(null)))
108108
;
109109
}
@@ -124,7 +124,7 @@ void setUp() {
124124
.andExpect(status().isInternalServerError())
125125
.andExpect(jsonPath("$.success", equalTo(false)))
126126
.andExpect(jsonPath("$.code", equalTo(4000)))
127-
.andExpect(jsonPath("$.msg", equalTo("지원하지 않는 상태코드")))
127+
.andExpect(jsonPath("$.msg", equalTo("지원하지 않는 상태코드: 메시지")))
128128
.andExpect(jsonPath("$.data", equalTo(null)))
129129
;
130130
}
@@ -145,7 +145,7 @@ void setUp() {
145145
.andExpect(status().isNotImplemented())
146146
.andExpect(jsonPath("$.success", equalTo(false)))
147147
.andExpect(jsonPath("$.code", equalTo(501)))
148-
.andExpect(jsonPath("$.msg", equalTo("Unhandled Exception")))
148+
.andExpect(jsonPath("$.msg", equalTo("Unhandled Exception: " + "메시지")))
149149
.andExpect(jsonPath("$.data", equalTo(null)))
150150
;
151151
}

0 commit comments

Comments
 (0)