Skip to content

[REFACTOR] 코드 일관성 개선#11

Merged
soomin0209 merged 2 commits into
devfrom
refactor/code-consistency
May 11, 2026
Merged

[REFACTOR] 코드 일관성 개선#11
soomin0209 merged 2 commits into
devfrom
refactor/code-consistency

Conversation

@soomin0209
Copy link
Copy Markdown
Collaborator

@soomin0209 soomin0209 commented May 11, 2026

📝 작업 내용

GlobalExceptionHandler

  • GlobalExceptionHandler 메서드명 handle 접두어 + camelCase로 통일
  • CustomErrorAttributes 제거

###응답 형식 통일

  • 컨트롤러 성공 응답 메시지 ~했습니다 형식으로 통일
  • 테스트 코드 응답 메시지 assertions 동기화

✅ 체크리스트 (Checklist)

  • 브랜치 이름 규칙을 준수했나요? (예: feat/login)
  • 코딩 컨벤션을 준수했나요?
  • 기능에 대한 테스트 코드를 작성/수행했나요?
  • 불필요한 주석이나 로그(console.log)를 제거했나요?

Summary by CodeRabbit

  • 리팩토링
    • 알림 관련 작업(목록 조회, 읽음 처리, 개별 및 일괄 삭제)의 완료 메시지가 더 명확하고 구체적인 한국어로 개선되었습니다.
    • 예외 처리 및 오류 응답 로직이 전반적으로 개선되었습니다.

Review Change Stack

@soomin0209 soomin0209 added the Refactor 코드 개선 label May 11, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

개요

CustomErrorAttributes 컴포넌트를 제거하고 GlobalExceptionHandler의 예외 핸들러들을 일관된 명명 규칙으로 리팩토링했으며, NotificationController의 응답 메시지를 더 구체적인 한국어 표현으로 업데이트하고, 이에 맞춰 통합 테스트와 단위 테스트의 어설션을 수정했습니다.

변경사항

예외 처리 정제 및 알림 API 메시지 개선

Layer / File(s) 요약
예외 처리 리팩토링
src/main/java/com/example/auctionnotification/common/exception/CustomErrorAttributes.java, src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java
CustomErrorAttributes 클래스 제거; GlobalExceptionHandler의 예외 핸들러 메서드 6개를 handle* 명명 규칙으로 리팩토링; ServiceErrorException 로깅을 5xx/4xx 상태에 따라 조건부 처리; HttpRequestMethodNotSupportedException 응답 상태를 405에서 400으로 변경.
알림 컨트롤러 메시지 업데이트
src/main/java/com/example/auctionnotification/notification/controller/NotificationController.java
5개 엔드포인트의 성공 응답 메시지를 "요청 성공" 형식에서 "했습니다" 형식의 과거형으로 변경: 목록 조회, 읽음 처리, 전체 읽음 처리, 삭제, 전체 삭제.
테스트 어설션 업데이트
src/test/java/com/example/auctionnotification/notification/NotificationIntegrationTest.java, src/test/java/com/example/auctionnotification/notification/controller/NotificationControllerTest.java
통합 테스트 및 단위 테스트의 성공 응답 메시지 어설션을 새로운 메시지 문자열과 일치하도록 수정; 모든 알림 API 엔드포인트의 6가지 메시지 기대값 업데이트.

코드 리뷰 예상 시간

🎯 2 (단순) | ⏱️ ~12분

관련 PR

  • GigaMak2/auction-notification#3: CustomErrorAttributes, GlobalExceptionHandler, NotificationController 등 동일한 예외 처리 및 알림 관련 클래스를 수정하는 관련 PR입니다.
  • GigaMak2/auction-notification#8: NotificationController 응답 메시지 및 테스트 어설션의 변경사항이 이 PR에서 도입된 컨트롤러 엔드포인트와 테스트 케이스를 직접 수정합니다.

추천 리뷰어

  • imprity
  • hhjo96
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.04% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 PR의 주요 변경사항을 포괄적으로 설명하고 있습니다. 코드 일관성 개선이라는 핵심 목표를 명확하게 반영하고 있습니다.
Description check ✅ Passed 설명이 PR의 모든 주요 변경사항(GlobalExceptionHandler 메서드명 통일, CustomErrorAttributes 제거, 응답 메시지 형식 통일)을 상세히 포함하고 있으며 체크리스트도 완성되어 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/code-consistency

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java`:
- Line 63: The handler for HttpRequestMethodNotSupportedException in
GlobalExceptionHandler is returning HttpStatus.BAD_REQUEST; change it to return
HttpStatus.METHOD_NOT_ALLOWED instead so the response status conforms to RFC
7231 and Spring conventions—locate the return statement that builds the
ResponseEntity (the line using
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(...))) and
replace HttpStatus.BAD_REQUEST with HttpStatus.METHOD_NOT_ALLOWED while keeping
the existing body payload and message intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f909c666-c45c-426e-a757-0714ea2c8c43

📥 Commits

Reviewing files that changed from the base of the PR and between a0f7bfe and ddbd33a.

📒 Files selected for processing (5)
  • src/main/java/com/example/auctionnotification/common/exception/CustomErrorAttributes.java
  • src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java
  • src/main/java/com/example/auctionnotification/notification/controller/NotificationController.java
  • src/test/java/com/example/auctionnotification/notification/NotificationIntegrationTest.java
  • src/test/java/com/example/auctionnotification/notification/controller/NotificationControllerTest.java
💤 Files with no reviewable changes (1)
  • src/main/java/com/example/auctionnotification/common/exception/CustomErrorAttributes.java

public ResponseEntity<BaseResponse<Void>> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
log.error("지원하지 않는 메소드 에러 발생 : ", e);
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# HttpRequestMethodNotSupportedException이 발생하는 컨텍스트 확인
rg -n -C3 --type=java "HttpRequestMethodNotSupportedException"

Repository: GigaMak2/auction-notification

Length of output: 2461


🏁 Script executed:

# Check if there are any tests for this exception handler
fd -e java -e groovy -e xml | xargs grep -l "HttpRequestMethodNotSupportedException\|handleHttpRequestMethodNotSupportedException" 2>/dev/null | head -20

Repository: GigaMak2/auction-notification

Length of output: 164


🏁 Script executed:

# Check what status code Spring uses by default for this exception
rg -n "METHOD_NOT_ALLOWED" --type=java | head -20

Repository: GigaMak2/auction-notification

Length of output: 55


🏁 Script executed:

# Look for other exception handlers to understand the pattern
rg -B2 -A5 "@ExceptionHandler" --type=java src/main/java/com/example/auctionnotification/common/exception/ 2>/dev/null

Repository: GigaMak2/auction-notification

Length of output: 8642


🌐 Web query:

Spring HttpRequestMethodNotSupportedException default HTTP status code RFC 7231

💡 Result:

Spring HttpRequestMethodNotSupportedException default HTTP status code: 405 (Method Not Allowed) [1][2]. How this relates to RFC 7231: - RFC 7231 specifies that if a server receives a request method that is known but not allowed for the target resource, it SHOULD respond with 405 (Method Not Allowed) [2]. Spring details: - In Spring Framework, HttpRequestMethodNotSupportedException implements ErrorResponse and its getStatusCode returns HttpStatus.METHOD_NOT_ALLOWED (405) [1][3].

Citations:


HTTP 상태 코드가 HTTP 표준 및 Spring Framework 설계에 맞지 않습니다.

HttpRequestMethodNotSupportedException의 응답 상태 코드를 400(Bad Request)에서 405(Method Not Allowed)로 변경해야 합니다.

문제점:

  • Spring Framework의 HttpRequestMethodNotSupportedException은 기본적으로 405 상태 코드를 반환하도록 설계되었습니다
  • RFC 7231에서는 리소스가 해당 HTTP 메서드를 지원하지 않을 때 405 Method Not Allowed를 사용하도록 명시합니다
  • 현재 사용 중인 400 Bad Request는 요청 구문이 잘못되었을 때 사용되는 상태 코드입니다
  • 이 변경사항은 API 계약을 변경하여 405 상태 코드에 의존하는 클라이언트의 오류 처리 로직을 깨뜨립니다
제안하는 수정
-        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다"));
+        return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다"));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다"));
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다"));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java`
at line 63, The handler for HttpRequestMethodNotSupportedException in
GlobalExceptionHandler is returning HttpStatus.BAD_REQUEST; change it to return
HttpStatus.METHOD_NOT_ALLOWED instead so the response status conforms to RFC
7231 and Spring conventions—locate the return statement that builds the
ResponseEntity (the line using
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(...))) and
replace HttpStatus.BAD_REQUEST with HttpStatus.METHOD_NOT_ALLOWED while keeping
the existing body payload and message intact.

Copy link
Copy Markdown
Contributor

@imprity imprity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@soomin0209 soomin0209 merged commit 13cb62b into dev May 11, 2026
2 checks passed
@soomin0209 soomin0209 deleted the refactor/code-consistency branch May 11, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor 코드 개선

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants