Conversation
📝 WalkthroughWalkthrough새로운 에러 처리 구조를 추가합니다: Changes
Sequence DiagramsequenceDiagram
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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()형태를 사용하고,ErrorResponse는getCode(),getMessage()형태를 사용합니다. 기능적으로 문제는 없으나, 두 인터페이스 간 네이밍 스타일 통일을 고려해볼 수 있습니다. 다만 DTO/Response 객체에서는 getter 스타일이 일반적이므로 현재 구조도 합리적입니다.src/main/java/knu/chcse/knucseofficialserver/global/exception/BusinessException.java (1)
10-13: null 안전성 검토 권장.
errorCode가null로 전달될 경우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; }
✨ 구현한 기능
📢 논의하고 싶은 내용
🎸 기타
Summary by CodeRabbit
새로운 기능
개선사항