Skip to content

Feat/#2 error exception#6

Merged
wlgns12370 merged 14 commits intomainfrom
feat/#2-error-exception
Feb 7, 2026
Merged

Feat/#2 error exception#6
wlgns12370 merged 14 commits intomainfrom
feat/#2-error-exception

Conversation

@letsgojh
Copy link
Contributor

@letsgojh letsgojh commented Feb 2, 2026

✨ 구현한 기능

📢 논의하고 싶은 내용

🎸 기타

Summary by CodeRabbit

  • 새로운 기능

    • 애플리케이션의 전역 오류 처리기가 도입되어 예외 발생 시 일관된 형식(code, message)의 오류 응답이 반환됩니다.
    • 비즈니스 예외 유형이 명확히 구분되어, 사용자에게 전달되는 오류 메시지와 코드가 더 명확해졌습니다.
  • 개선사항

    • 모든 오류 응답이 통합되어 예측 가능한 오류 정보를 제공합니다.

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

새로운 에러 처리 구조를 추가합니다: ErrorCode, ErrorResponse 인터페이스, ErrorResponseImpl 구현체, BusinessException 커스텀 예외, 그리고 전역 예외 처리용 GlobalExceptionHandler가 도입되었습니다.

Changes

Cohort / File(s) Summary
에러 처리 계약
src/main/java/knu/chcse/knucseofficialserver/global/error/ErrorCode.java, src/main/java/knu/chcse/knucseofficialserver/global/error/ErrorResponse.java
에러 정보를 표현하는 두 인터페이스 추가 (ErrorCode : code(), message() / ErrorResponse : getCode(), getMessage()).
에러 응답 구현
src/main/java/knu/chcse/knucseofficialserver/global/error/ErrorResponseImpl.java
ErrorResponse 구현체 추가. code/message 필드와 빌더 및 getter 제공(롬복 사용).
예외 처리 흐름
src/main/java/knu/chcse/knucseofficialserver/global/exception/BusinessException.java, src/main/java/knu/chcse/knucseofficialserver/global/exception/GlobalExceptionHandler.java
BusinessException 커스텀 예외 추가(내부에 ErrorCode 보유). GlobalExceptionHandler에서 BusinessException을 잡아 ErrorResponseImpl로 변환하여 HTTP 응답으로 반환.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Controller
    participant BusinessException
    participant GlobalExceptionHandler
    participant ErrorResponseImpl

    Client->>Controller: HTTP request
    Controller->>Controller: (비즈니스 로직) throw BusinessException(errorCode)
    Controller-->>GlobalExceptionHandler: BusinessException 발생
    GlobalExceptionHandler->>BusinessException: getCode(), getMessage()
    BusinessException-->>GlobalExceptionHandler: code, message
    GlobalExceptionHandler->>ErrorResponseImpl: build(code, message)
    ErrorResponseImpl-->>GlobalExceptionHandler: ErrorResponse
    GlobalExceptionHandler-->>Client: HTTP error response (body: ErrorResponse)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 나는 깡충, 에러를 모아,
코드와 메시지로 정리하네.
예외가 뛰어나면 나는 잡고,
핸들러가 응답을 돌려주네.
새 구조로 산책 시작해요 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 제목이 PR의 주요 변경사항(에러 처리 구조 구현)을 명확히 나타내고 있으나 다소 모호합니다. 더 구체적인 제목으로 변경하세요. 예: 'feat: Add error handling structure with ErrorCode, ErrorResponse, and GlobalExceptionHandler'
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed PR 설명이 템플릿을 따르고 구현한 기능을 명확히 나열하고 있습니다.
Linked Issues check ✅ Passed 모든 코드 변경사항이 이슈 #5의 요구사항(ErrorCode, BusinessException, GlobalExceptionHandler, ErrorResponse)을 충족합니다.
Out of Scope Changes check ✅ Passed PR의 모든 변경사항이 이슈 #5의 에러 처리 구조 설계 범위 내에 있습니다.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/#2-error-exception

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

@letsgojh letsgojh marked this pull request as ready for review February 2, 2026 08:31
Copy link

@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: 2

🤖 Fix all issues with AI agents
In
`@src/main/java/knu/chcse/knucseofficialserver/global/exception/GlobalExceptionHandler.java`:
- Line 6: Remove the unused import
org.springframework.web.bind.annotation.RestController from
GlobalExceptionHandler.java; open the class GlobalExceptionHandler and delete
the unused RestController import statement so the file only contains necessary
imports and no unused references.
- Around line 12-18: The handler handleCustomRuntimeException currently returns
ErrorResponseImpl without an HTTP status so callers get 200 OK; change it to
return a ResponseEntity<ErrorResponse> (or annotate with `@ResponseStatus`) and
set the status from the BusinessException's ErrorCode (add a status() HttpStatus
accessor to ErrorCode if needed) so responses include the correct HTTP status;
update the method signature in GlobalExceptionHandler to use ResponseEntity and
build the response with ErrorResponseImpl.builder() and
ResponseEntity.status(errorCode.status()).body(...), referencing
BusinessException, handleCustomRuntimeException, ErrorResponse,
ErrorResponseImpl, and ErrorCode.
🧹 Nitpick comments (2)
src/main/java/knu/chcse/knucseofficialserver/global/error/ErrorResponse.java (1)

3-6: 네이밍 일관성 검토 권장.

ErrorCode 인터페이스는 code(), message() 형태를 사용하고, ErrorResponsegetCode(), getMessage() 형태를 사용합니다. 기능적으로 문제는 없으나, 두 인터페이스 간 네이밍 스타일 통일을 고려해볼 수 있습니다. 다만 DTO/Response 객체에서는 getter 스타일이 일반적이므로 현재 구조도 합리적입니다.

src/main/java/knu/chcse/knucseofficialserver/global/exception/BusinessException.java (1)

10-13: null 안전성 검토 권장.

errorCodenull로 전달될 경우 NullPointerException이 발생합니다. 방어적 프로그래밍 관점에서 null 체크를 추가하거나, 생성자에서 Objects.requireNonNull()을 사용하여 명확한 예외 메시지를 제공하는 것을 고려해볼 수 있습니다.

💡 개선 예시
+import java.util.Objects;
+
 `@Getter`
 public class BusinessException extends RuntimeException {
     private final ErrorCode errorCode;

     public BusinessException(ErrorCode errorCode) {
+        Objects.requireNonNull(errorCode, "ErrorCode must not be null");
         super(errorCode.message());
         this.errorCode = errorCode;
     }

Copy link
Member

@wlgns12370 wlgns12370 left a comment

Choose a reason for hiding this comment

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

규칙 잘 지켜주셨네요 수고하셨습니다!

@wlgns12370 wlgns12370 merged commit 5dacf34 into main Feb 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🛠 기능 구현] 에러 코드 및 예외 처리 구조 설계

2 participants