[회원 관리 기능 추가] MemberController에 로그아웃 API 추가 및 ApiResponseDto의 fail 메서드 오버로딩으로 응답 처리 개선. CustomAuthenticationFailureHandler, GlobalExceptionHandler, JwtAccessDeniedHandler에서 null 데이터 제거로 응답 일관성 향상.

This commit is contained in:
2025-08-20 10:18:54 +09:00
parent 33b33ef7a3
commit bfb87b8e33
4 changed files with 13 additions and 5 deletions

View File

@@ -30,9 +30,17 @@ public class ApiResponseDto<T> {
return new ApiResponseDto<T>(SUCCESS, responseCode.name(), responseCode.getDescription(), data); return new ApiResponseDto<T>(SUCCESS, responseCode.name(), responseCode.getDescription(), data);
} }
public static <T> ApiResponseDto<T> success(ApiResponseCode responseCode) {
return new ApiResponseDto<T>(SUCCESS, responseCode.name(), responseCode.getDescription(), null);
}
public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode, T data) { public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode, T data) {
return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data); return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
} }
public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode) {
return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
}
} }

View File

@@ -38,12 +38,12 @@ public class CustomAuthenticationFailureHandler implements AuthenticationFailure
ApiResponseDto<String> apiResponse; ApiResponseDto<String> apiResponse;
if (exception instanceof UsernameNotFoundException) { if (exception instanceof UsernameNotFoundException) {
apiResponse = ApiResponseDto.fail(ApiResponseCode.USER_NOT_FOUND, null); apiResponse = ApiResponseDto.fail(ApiResponseCode.USER_NOT_FOUND);
} else if (exception instanceof BadCredentialsException) { } else if (exception instanceof BadCredentialsException) {
apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_UNAUTHORIZED, null); apiResponse = ApiResponseDto.fail(ApiResponseCode.COMMON_UNAUTHORIZED);
} else { } else {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); 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); String jsonResponse = objectMapper.writeValueAsString(apiResponse);

View File

@@ -14,7 +14,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(ApiException.class) @ExceptionHandler(ApiException.class)
public ResponseEntity<ApiResponseDto<Void>> handleApiException(ApiException e) { public ResponseEntity<ApiResponseDto<Void>> handleApiException(ApiException e) {
ApiResponseDto<Void> response = ApiResponseDto.fail(e.getResponseCode(), null); ApiResponseDto<Void> response = ApiResponseDto.fail(e.getResponseCode());
return ResponseEntity.status(e.getResponseCode().getStatusCode()).body(response); return ResponseEntity.status(e.getResponseCode().getStatusCode()).body(response);
} }

View File

@@ -35,7 +35,7 @@ public class JwtAccessDeniedHandler implements AccessDeniedHandler {
} else { } else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.setContentType(MediaType.APPLICATION_JSON_VALUE); 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));
} }
} }
} }