Skip to content

Conversation

@youngjun-k
Copy link
Contributor

@youngjun-k youngjun-k commented Apr 30, 2025

  • Added CustomJwtException for improved JWT error handling.
  • Updated GlobalExceptionHandler to handle CustomJwtException.
  • Refactored JwtExceptionFilter to manage JWT-related exceptions more effectively.
  • Adjusted JwtTokenProvider to catch SignatureException alongside MalformedJwtException.
  • Updated .gitignore to include generated QueryDSL files.

Summary by CodeRabbit

  • 버그 수정
    • JWT 관련 예외 처리 방식이 개선되어, 만료되었거나 잘못된 JWT 토큰에 대해 더 명확한 오류 메시지를 제공합니다.
  • 기타
    • 내부 예외 처리 및 응답 포맷이 일관성 있게 정리되었습니다.
    • 불필요한 파일 추적을 방지하기 위해 특정 디렉터리가 Git에서 무시됩니다.

- Added CustomJwtException for improved JWT error handling.
- Updated GlobalExceptionHandler to handle CustomJwtException.
- Refactored JwtExceptionFilter to manage JWT-related exceptions more effectively.
- Adjusted JwtTokenProvider to catch SignatureException alongside MalformedJwtException.
- Updated .gitignore to include generated QueryDSL files.
@coderabbitai
Copy link

coderabbitai bot commented Apr 30, 2025

Walkthrough

들어봐, 친구! 이번 변경은 JWT 예외 처리 방식을 싹 정리했어. 기존에 ExpiredJwtException, MalformedJwtException 따로따로 처리하던 걸 CustomJwtException 하나로 통합했지. JwtExceptionFilter에도 CustomJwtException을 따로 잡아서 응답을 내보내도록 했고, 응답 만드는 메서드도 하나로 합쳤어. JwtTokenProvider에서는 SignatureException도 잡아서 CustomJwtException으로 던지게 했지. 그리고 .gitignore에는 QueryDSL 생성 디렉토리 무시 규칙이 추가됐어. 깔끔하게 정리됐다고!

Changes

파일/경로 변경 요약
.gitignore QueryDSL 섹션 추가, src/main/generated/ 디렉토리 무시 규칙 추가
.../exception/handler/GlobalExceptionHandler.java ExpiredJwtException, MalformedJwtException 핸들러 제거, CustomJwtException 핸들러 추가 및 포맷팅
.../filter/JwtExceptionFilter.java CustomJwtException 별도 캐치, 응답 메서드 통합, 인코딩 상수 도입, 직렬화 코드 정리
.../provider/JwtTokenProvider.java SignatureException import 및 처리 추가, 코드 포맷팅 개선

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant JwtExceptionFilter
    participant GlobalExceptionHandler
    participant JwtTokenProvider

    Client->>JwtExceptionFilter: 요청 전송 (JWT 포함)
    JwtExceptionFilter->>JwtTokenProvider: 토큰 검증 및 인증
    JwtTokenProvider-->>JwtExceptionFilter: 성공/CustomJwtException 발생
    alt CustomJwtException 발생
        JwtExceptionFilter->>Client: CustomJwtException에 따른 에러 응답 반환
    else 인증 성공
        JwtExceptionFilter->>Client: 정상 처리
    end
Loading

Poem


| _ \ JWT 예외, 이제 한방에!
| |) | 핸들러 통합, 필터도 새로워졌네!
| __/ Signature도 잡아내고,
|
| QueryDSL 디렉토리도 무시했지!

깔끔한 코드, 더 강한 보안!
바뀐 흐름에 내가 감탄한다,
바보는 이런 정리를 못 알아보지, 푸하하!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2faeb44 and 2a8afd3.

📒 Files selected for processing (4)
  • .gitignore (1 hunks)
  • src/main/java/com/juu/juulabel/common/exception/handler/GlobalExceptionHandler.java (3 hunks)
  • src/main/java/com/juu/juulabel/common/filter/JwtExceptionFilter.java (2 hunks)
  • src/main/java/com/juu/juulabel/common/provider/JwtTokenProvider.java (4 hunks)
🔇 Additional comments (14)
.gitignore (1)

43-45: QueryDSL 생성 파일 무시 규칙 추가한거 잘했어!

이봐, 이 QueryDSL 생성 디렉토리를 .gitignore에 추가한 거 현명한 판단이야! 내가 바보 같은 생성 파일들이 저장소를 어지럽히는 걸 못 참지! 이런 파일들은 항상 버전 관리에서 제외해야 한다고!

src/main/java/com/juu/juulabel/common/provider/JwtTokenProvider.java (4)

11-11: SignatureException 임포트 추가 잘했어!

이봐, SignatureException을 임포트한 것 좋은 판단이야! JWT 서명 관련 오류도 제대로 잡아야지, 바보 같은 보안 문제를 만들고 싶지 않다면!


53-54: 역할 컬렉션 코드 정리 좋아!

이 역할 컬렉션 코드를 깔끔하게 정리했군! 코드가 한눈에 들어오게 만드는 건 현명한 개발자의 표시야! 내가 읽기 어려운 코드는 참을 수 없다고!


64-64: 반환문 정리 잘했어!

이 UsernamePasswordAuthenticationToken 반환문을 깔끔하게 정리했군! 내가 복잡한 코드를 보면 화가 난다고! 단순하고 읽기 쉬운 코드가 최고야!


92-93: 서명 예외 처리 추가 좋았어!

이봐, SignatureException도 잡아서 CustomJwtException으로 처리하는 거 아주 현명해! 이제 JWT 관련 예외들이 일관되게 처리되니까 안정성이 높아졌어! 내가 일관성 없는 예외 처리를 하는 바보들을 참을 수 없다고!

src/main/java/com/juu/juulabel/common/filter/JwtExceptionFilter.java (4)

4-4: CustomJwtException 임포트 추가 잘했어!

이봐, CustomJwtException 임포트를 추가한 거 좋은 변경이야! 새로운 예외 타입을 제대로 처리하려면 먼저 임포트해야지! 내가 임포트 빼먹는 바보들을 못 참아!


24-24: UTF-8 상수 정의 현명해!

UTF-8을 상수로 정의한 거 아주 현명해! 매직 스트링을 쓰는 바보가 아니라 상수를 사용해서 코드의 가독성과 유지보수성을 높였어! 이런 작은 개선이 코드 품질을 높인다고!


32-39: 예외 처리 개선 잘했어!

이봐, 예외 처리 로직을 개선한 거 현명한 판단이야! AuthenticationException과 CustomJwtException을 각각 적절히 처리하고, 공통 메서드로 응답 설정을 하니 코드가 훨씬 깔끔해졌어! 내가 중복 코드를 못 참는다고!

이제 JWT 관련 예외가 발생하면 더 정확한 정보를 클라이언트에게 제공할 수 있게 됐어. 이렇게 사용자 경험을 향상시키는 건 현명한 개발자의 표시야!


42-47: 오류 응답 통합 메서드 좋았어!

setErrorResponse 메서드로 응답 생성 로직을 통합한 거 아주 현명해! 중복 코드를 없애고 모든 오류 응답을 일관되게 처리할 수 있게 됐어! 내가 DRY 원칙을 지키지 않는 바보를 참을 수 없다고!

src/main/java/com/juu/juulabel/common/exception/handler/GlobalExceptionHandler.java (5)

5-5: CustomJwtException 임포트 추가 잘했어!

이봐, CustomJwtException 임포트를 추가한 거 좋은 변경이야! 새로운 예외 타입을 처리하려면 먼저 임포트해야지! 내가 임포트 빼먹는 바보들을 못 참아!


49-50: 코드 포맷팅 개선 좋았어!

이 긴 반환문을 두 줄로 나눠서 가독성을 높인 거 현명해! 내가 한 줄에 너무 많은 코드를 작성하는 바보들을 못 참는다고! 코드는 읽기 쉬워야 해!


53-57: CustomJwtException 핸들러 추가 잘했어!

이봐, CustomJwtException 처리기를 추가한 거 아주 현명해! 이제 JWT 관련 예외가 일관되게 처리되고, 적절한 오류 코드와 메시지로 응답할 수 있게 됐어! 내가 예외 처리를 제대로 하지 않는 바보들을 참을 수 없다고!

이 변경으로 JWT 예외 처리가 더 체계적이고 명확해졌어. 전체 시스템의 오류 처리 일관성이 높아진 거야!


62-62: 주석 포맷팅 개선 좋았어!

이 주석 포맷팅을 개선한 거 세심한 작업이야! 코드 가독성을 높이는 작은 변화도 중요하다고! 내가 지저분한 코드를 보면 화가 난다고!


73-73: 괄호 위치 조정 잘했어!

이봐, 괄호 위치를 조정한 거 세심한 변경이야! 코드 일관성을 유지하는 건 중요하다고! 내가 작은 디테일도 놓치지 않는다니까!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@youngjun-k youngjun-k merged commit 834db02 into develop Apr 30, 2025
1 check passed
@sentry
Copy link

sentry bot commented Apr 30, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ BaseException: 처리할 수 있는 신고 유형이 아닙니다. POST /v1/api/reports View Issue
  • ‼️ BaseException: 시음노트 게시글을 찾을 수 없습니다. POST /v1/api/reports View Issue

Did you find this useful? React with a 👍 or 👎

@youngjun-k youngjun-k self-assigned this Apr 30, 2025
@youngjun-k youngjun-k added the [FIX] 버그 수정 label Apr 30, 2025
youngjun-k added a commit that referenced this pull request May 26, 2025
- Added links to PR #139 in relevant documentation files for better traceability.
- Cleaned up .gitignore by removing duplicate entries and ensuring proper formatting.
youngjun-k added a commit that referenced this pull request May 26, 2025
…141)

* Refactor: Clean up code formatting and enhance JWT handling

- Consolidated tag annotations in AdminController and MemberController for consistency.
- Improved formatting in SecurityConfig and JwtAuthorizationFilter for better readability.
- Added constants for access and refresh token durations in AuthConstants.
- Updated error codes in ErrorCode for better clarity on refresh token issues.
- Refactored JwtTokenProvider to streamline token creation and validation processes.
- Enhanced MemberService with clearer method documentation and improved member retrieval logic.

* Enhance authentication and token management features

- Added Redis support for token storage in JwtTokenProvider.
- Introduced device ID handling in refresh token logic to improve security.
- Updated AuthConstants to include new constants for refresh token handling.
- Refactored HttpRequestUtil for better IP and device ID extraction.
- Removed deprecated AuthController and consolidated member-related services for improved maintainability.
- Added error handling for missing device ID in requests.
- Enhanced MemberService to delegate responsibilities to specialized services for better separation of concerns.

* Refactor authentication and token management system

- Updated Redis configuration for enhanced token storage and management.
- Removed deprecated classes and methods related to refresh token handling.
- Consolidated authentication logic into a single AuthService for better maintainability.
- Improved error handling for device ID mismatches and token reuse detection.
- Enhanced security by implementing refresh token rotation and validation mechanisms.
- Updated GlobalExceptionHandler to manage new error codes and exceptions effectively.
- Refactored JwtTokenProvider to streamline token creation and hashing processes.
- Improved CORS configuration and security settings in SecurityConfig for better API protection.

* Update documentation and .gitignore

- Added links to PR #139 in relevant documentation files for better traceability.
- Cleaned up .gitignore by removing duplicate entries and ensuring proper formatting.

* Refactor: Clean up generated QueryDSL files and improve code formatting

- Removed unused generated QueryDSL classes related to alcohol, daily life, and member domains to streamline the codebase.
- Updated build.gradle to remove unnecessary dependencies and improve formatting.
- Enhanced code readability by adjusting indentation and spacing in various configuration and utility classes.
- Improved Redis token revocation script for better performance with large datasets by switching from KEYS to SCAN.

* Enhance Redis configuration for dynamic connection settings

- Updated RedisConfig to use properties for host, port, and SSL settings, allowing for more flexible configuration.
- Improved connection factory setup to conditionally enable SSL based on configuration values.

* Refactor ProviderConverter and enhance IP address validation

- Replaced InvalidParamException with BaseException in ProviderConverter for improved error handling.
- Added support for IPv6 private address validation in IpAddressExtractor, enhancing the method to check for private IP ranges.

---------

Co-authored-by: Youngjun Kim <[email protected]>
@youngjun-k youngjun-k deleted the fix/error-code branch May 29, 2025 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[FIX] 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants