Skip to content

feat(error): 공통 예외 처리 + 커스텀 ErrorCode 도입 - #18

Merged
Ji-InPark merged 10 commits into
mainfrom
feat/error-code-advice-main
Jul 27, 2026
Merged

feat(error): 공통 예외 처리 + 커스텀 ErrorCode 도입#18
Ji-InPark merged 10 commits into
mainfrom
feat/error-code-advice-main

Conversation

@Ji-InPark

Copy link
Copy Markdown
Member

#17을 development에 잘못 머지해 되돌리고, main 대상으로 다시 올립니다. 동일 작업(10 commits) + Security 계층 인증 실패 code 처리까지 포함. main 베이스에서 ./gradlew clean build 그린 확인.

Summary

백엔드가 에러를 HTTP status로만 내려주던 것을 개선해, 모든 에러 응답에 안정적인 기계 판독용 code를 추가합니다.

  • 중앙 ErrorCode enum (32개 = code + HTTP status + 기본 메시지 단일 소스). 비즈니스 예외 30개 + 인증 실패 2개(AUTHENTICATION_REQUIRED, ACCESS_DENIED)
  • 분산된 커스텀 예외 26개 → 단일 CustomException(errorCode) 통합, 클래스 전부 삭제
  • GlobalExceptionHandler(@RestControllerAdvice, ResponseEntityExceptionHandler 상속): 커스텀 / @Valid·ConstraintViolation(필드 errors[]) / 프레임워크 예외(status 보존) / fallback 500
  • JWT 필터 예외 → HandlerExceptionResolver 위임(401 유지). 추가로 Security 계층 인증/인가 실패도 AuthenticationEntryPoint/AccessDeniedHandler로 code를 실어줌(advice 우회 경로 커버)

응답 스키마 (순수 상위집합 · 하위호환)

{ code, message, status, path, timestamp, errors[] } — 모든 예외의 HTTP status 그대로 보존, 기존 message/status 유지, code/errors만 추가.

보안

  • validation 필드 에러에서 @Masked 필드(비밀번호) raw 값 redaction → 응답/로그 유출 방지

Test plan

  • ./gradlew clean build (main 베이스) — 전체 테스트 그린
  • 로컬 기동 후 실제 응답 바디 code/errors 확인 (DB/Redis 필요)
  • 무효·만료·미인증 JWT → AUTHENTICATION_REQUIRED(401) / 권한 부족 → ACCESS_DENIED(403) / 삭제 사용자 → INVALID_JWT 확인

연계

  • 프론트 PR(KioSchool#527)이 이 code를 미러링해 소비. 새 code 2개(AUTHENTICATION_REQUIRED·ACCESS_DENIED)는 프론트 미러에도 추가 필요 → 백엔드 배포 순서 조율.

🤖 Generated with Claude Code

Ji-InPark and others added 10 commits July 27, 2026 22:20
Replace UserNotFoundException, LoginFailedException, NoPermissionException,
and RegisterException with CustomException + ErrorCode across throw sites
(UserService, EmailService) and their test assertions (UserServiceTest,
UserFacadeTest, WorkspaceFacadeTest, EmailServiceTest). Deletes the four
now-unused exception classes.
Register a custom AuthenticationEntryPoint (401 AUTHENTICATION_REQUIRED)
and AccessDeniedHandler (403 ACCESS_DENIED) that write the same
ErrorResponse JSON. Closes the gap where missing/expired-token denials
(handled by Spring Security before DispatcherServlet) bypassed the
@RestControllerAdvice and returned an empty, code-less body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Ji-InPark
Ji-InPark merged commit 427a1c6 into main Jul 27, 2026
1 check passed
@Ji-InPark
Ji-InPark deleted the feat/error-code-advice-main branch July 27, 2026 13:23
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.

1 participant