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)); } } }