Repository navigation
fix: 배지 조회 응답 상태코드 정정 — 미가입 404 통일 및 라우팅 미스 4xx - #21
Merged
Merged
Conversation
미가입 username은 이제 모든 테마에서 404 BADGE_001을 받는다. 가입했지만 자격이 없는 경우는 기존대로 200 잠금 SVG다. 기존에는 자격이 필요한 테마(beta-tester)만 200 잠금 SVG를 반환했다. 자격 게이트가 사용자 조회보다 먼저 걸려 오타 username이 걸러지지 않았다. findGrant 쿼리에 userExists 컬럼을 더해 DB 왕복을 늘리지 않고 판별하며, BadgeRenderService가 자격 분기보다 앞에서 BADGE_001을 던진다.
/badge/ 같은 라우팅 미스는 404 NOT_FOUND를, POST /badge/{username} 은
405 METHOD_NOT_ALLOWED를 반환한다. ERROR 스택트레이스도 남지 않는다.
기존에는 GlobalExceptionHandler의 catch-all이 Spring MVC 표준 예외까지
삼켜 전부 500 SERVER_ERROR로 나갔다. /badge/** 가 permitAll이라
미인증 요청만으로 ERROR 로그를 쌓을 수 있었다.
ErrorResponse를 구현하는 예외 5종을 전용 핸들러로 잡고, 응답 코드와
메시지를 예외가 지정한 상태에서 파생해 매핑 표 없이 처리한다.
2 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🏷️ 작업 유형
📋 변경 사항
배지 조회가 잘못된 상태코드를 주던 문제 두 건을 고쳤습니다.
1. 미가입 사용자 응답을 404로 통일 (cc71356)
미가입 username은 이제 모든 테마에서 404
BADGE_001을 받습니다. 가입했지만 자격이 없는 경우는 기존대로 200 잠금 SVG입니다.?theme=gpuBADGE_001BADGE_001?theme=beta-testerBADGE_001?theme=beta-tester자격 게이트가 사용자 조회보다 먼저 걸려 오타 username이 "전용 배지" 안내로 지나갔습니다.
findGrant네이티브 쿼리에userExists컬럼을 더해 DB 왕복을 늘리지 않고 판별하고,BadgeRenderService가 자격 분기보다 앞에서BADGE_001을 던집니다.2. 라우팅 미스가 500 대신 올바른 4xx 반환 (193b976)
develop에도 있던 기존 결함으로, 1번 검증 중에 발견했습니다.GET /badge/,/badge,/badge/{u}/SERVER_ERRORNOT_FOUNDPOST /badge/{u}SERVER_ERRORMETHOD_NOT_ALLOWEDGlobalExceptionHandler의@ExceptionHandler(Exception.class)catch-all이 Spring MVC 표준 예외까지 삼켰습니다./badge/**가permitAll이라 미인증 요청만으로 ERROR 스택트레이스를 쌓을 수 있었습니다.ErrorResponse를 구현하는 예외 5종을 전용 핸들러로 잡고, 응답 코드와 메시지를 예외가 지정한 상태에서 파생해 매핑 표 없이 처리합니다.3.
.omc/를 gitignore에 추가 (33acaf9)에이전트 하네스가 생성하는 로컬 디렉터리입니다.
리뷰 시 알아둘 점
BADGES.md:209의 locked 배지 예시 이미지가 깨집니다.octocat이 미가입이라 200 잠금 SVG를 받고 있었는데, 1번 변경으로 404가 됩니다. 문서를 그대로 두고 배포하기로 결정된 사항입니다.HttpMediaTypeNotAcceptableException등 3종은 현재 라우트에서 도달 불가라 테스트가 없습니다. 같은ServletException implements ErrorResponse계열이라 핸들러 목록에만 넣어둔 방어 코드입니다.✅ 테스트
TDD로 진행했고 사이클마다 RED를 확인했습니다.
Null return value from advice ... getUserExists()Expecting value to be false but was trueExpecting code to raise a throwable.Status expected:<404> but was:<500>신규 테스트가 실제로 태우는 계약입니다.
UserBadgeGrantRepositoryIntegrationTest— 실 Postgres로userExistsalias ↔ getter 매핑 검증GlobalExceptionHandlerWebMvcTest—@WebMvcTest로 실제 디스패치를 태워 핸들러 도달 경로 검증BadgeRenderServiceTest— 미가입 시 잠금 렌더·캐시·집계 조회 미호출 검증