From bfb87b8e33298d7371c4e493edb451491651685c Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 20 Aug 2025 10:18:54 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=9A=8C=EC=9B=90=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80]=20MemberController?= =?UTF-8?q?=EC=97=90=20=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20ApiResponseDto=EC=9D=98=20fail?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=98=A4=EB=B2=84=EB=A1=9C?= =?UTF-8?q?=EB=94=A9=EC=9C=BC=EB=A1=9C=20=EC=9D=91=EB=8B=B5=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B0=9C=EC=84=A0.=20CustomAuthenticationFailureHa?= =?UTF-8?q?ndler,=20GlobalExceptionHandler,=20JwtAccessDeniedHandler?= =?UTF-8?q?=EC=97=90=EC=84=9C=20null=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=EB=A1=9C=20=EC=9D=91=EB=8B=B5=20=EC=9D=BC?= =?UTF-8?q?=EA=B4=80=EC=84=B1=20=ED=96=A5=EC=83=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bio/bio_backend/global/dto/ApiResponseDto.java | 8 ++++++++ .../exception/CustomAuthenticationFailureHandler.java | 6 +++--- .../global/exception/GlobalExceptionHandler.java | 2 +- .../global/exception/JwtAccessDeniedHandler.java | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java index baebd96..d3538ee 100644 --- a/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java +++ b/src/main/java/com/bio/bio_backend/global/dto/ApiResponseDto.java @@ -30,9 +30,17 @@ public class ApiResponseDto { return new ApiResponseDto(SUCCESS, responseCode.name(), responseCode.getDescription(), data); } + public static ApiResponseDto success(ApiResponseCode responseCode) { + return new ApiResponseDto(SUCCESS, responseCode.name(), responseCode.getDescription(), null); + } + public static ApiResponseDto fail(ApiResponseCode responseCode, T data) { return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); } + public static ApiResponseDto fail(ApiResponseCode responseCode) { + return new ApiResponseDto(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null); + } + } diff --git a/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java b/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java index 2cc9ceb..624de5b 100644 --- a/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java +++ b/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java @@ -38,12 +38,12 @@ public class CustomAuthenticationFailureHandler implements AuthenticationFailure ApiResponseDto apiResponse; if (exception instanceof UsernameNotFoundException) { - apiResponse = ApiResponseDto.fail(ApiResponseCode.USER_NOT_FOUND, null); + apiResponse = ApiResponseDto.fail(ApiResponseCode.USER_NOT_FOUND); } else if (exception instanceof BadCredentialsException) { - apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_UNAUTHORIZED, null); + apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_UNAUTHORIZED); } else { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); - apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_INTERNAL_SERVER_ERROR, null); + apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_INTERNAL_SERVER_ERROR); } String jsonResponse = objectMapper.writeValueAsString(apiResponse); diff --git a/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java index 5cc592e..5abcddc 100644 --- a/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java @@ -14,7 +14,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(ApiException.class) public ResponseEntity> handleApiException(ApiException e) { - ApiResponseDto response = ApiResponseDto.fail(e.getResponseCode(), null); + ApiResponseDto response = ApiResponseDto.fail(e.getResponseCode()); return ResponseEntity.status(e.getResponseCode().getStatusCode()).body(response); } diff --git a/src/main/java/com/bio/bio_backend/global/exception/JwtAccessDeniedHandler.java b/src/main/java/com/bio/bio_backend/global/exception/JwtAccessDeniedHandler.java index 3056d84..26251e8 100644 --- a/src/main/java/com/bio/bio_backend/global/exception/JwtAccessDeniedHandler.java +++ b/src/main/java/com/bio/bio_backend/global/exception/JwtAccessDeniedHandler.java @@ -35,7 +35,7 @@ public class JwtAccessDeniedHandler implements AccessDeniedHandler { } else { response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setContentType(MediaType.APPLICATION_JSON_VALUE); - new ObjectMapper().writeValue(response.getWriter(), ApiResponseDto.fail(ApiResponseCode.COMMON_FORBIDDEN, null)); + new ObjectMapper().writeValue(response.getWriter(), ApiResponseDto.fail(ApiResponseCode.COMMON_FORBIDDEN)); } } }