[회원 관리 기능 추가] MemberController에 로그아웃 API 추가 및 ApiResponseDto의 fail 메서드 오버로딩으로 응답 처리 개선. CustomAuthenticationFailureHandler, GlobalExceptionHandler, JwtAccessDeniedHandler에서 null 데이터 제거로 응답 일관성 향상.
This commit is contained in:
@@ -30,9 +30,17 @@ public class ApiResponseDto<T> {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -38,12 +38,12 @@ public class CustomAuthenticationFailureHandler implements AuthenticationFailure
|
||||
|
||||
ApiResponseDto<String> 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);
|
||||
|
@@ -14,7 +14,7 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(ApiException.class)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user