Skip to content

Commit 5ed0736

Browse files
authored
fix: API 응답 실패 시, 이유 추가 (#65)
1 parent b2970d0 commit 5ed0736

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

auth/src/main/java/com/jocketdan/auth/dto/CommonResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public static <T> CommonResponse<T> success(T data) {
2020
public static <T> CommonResponse<T> fail(String message) {
2121
return new CommonResponse<>(false, message, null);
2222
}
23+
24+
public static <T> CommonResponse<T> fail(String message, T reason) {
25+
return new CommonResponse<>(false, message, reason);
26+
}
2327
}

auth/src/main/java/com/jocketdan/auth/handlers/GlobalExceptionHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ public ResponseEntity<CommonResponse<Void>> handleValidationException(MethodArgu
7474

7575
// 그 외 모든 예상치 못한 예외
7676
@ExceptionHandler(Exception.class)
77-
public ResponseEntity<CommonResponse<Void>> handleGlobalException(Exception e) {
77+
public ResponseEntity<CommonResponse<String>> handleGlobalException(Exception e) {
7878
log.error("서버 오류", e);
79-
return new ResponseEntity<>(CommonResponse.fail("서버 내부 오류가 발생했습니다."), HttpStatus.INTERNAL_SERVER_ERROR);
79+
String reason = String.format("[%s] %s", e.getClass().getSimpleName(), e.getMessage());
80+
81+
return new ResponseEntity<>(CommonResponse.fail("서버 내부 오류가 발생했습니다.", reason), HttpStatus.INTERNAL_SERVER_ERROR);
8082
}
8183
}

0 commit comments

Comments
 (0)