fix(api,validators,mobile): Prisma 에러 핸들링 강화 및 Query DTO 타입 안전성 개선 (#118)#119
Conversation
Prisma unique constraint 위반(P2002)을 자동으로 BusinessException으로 변환하는 로직 추가. 알려진 constraint는 구체적 에러코드로, 미지의 constraint는 SYS_0004로 폴백 처리.
auth, oauth, follow, notification 서비스에서 unique constraint 위반 (P2002) 발생 시 구체적인 BusinessException으로 변환하도록 개선. 동시 요청(race condition) 시에도 적절한 에러 응답을 반환. - auth.service: 이메일 중복 가입 시 emailAlreadyRegistered - oauth.service: 계정 연결 중복 시 provider별 alreadyLinked - follow.service: 중복 친구 요청 시 followRequestAlreadySent - notification.service: P2025만 무시하고 나머지 에러는 re-throw
- create/update에 P2002 race condition 방어 추가 - 삭제 시 할 일이 있으면 todoCategoryHasTodos(0855) 에러 반환 - moveToCategoryId가 삭제 대상과 같으면 invalidParameter(SYS_0002) 반환 - 컨트롤러 API 문서 에러 테이블 업데이트
컨트롤러에서 수동 string→number 파싱을 제거하고 Zod 스키마 기반 DTO로 교체하여 타입 안전성과 유효성 검증 강화. - validators: getCheersQuerySchema, getNudgesQuerySchema 추가 - api: GetCheersQueryDto, GetNudgesQueryDto 생성 - controller: @query() DTO 자동 파싱으로 전환
USER_0611, TODO_0810, TODO_CATEGORY_0851~0856 에러코드에 대한 사용자 친화적 한국어 메시지 추가.
Summary of ChangesHello @dydals3440, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 Pull Request는 백엔드 API의 견고성을 크게 향상시키고, 모바일 앱의 사용자 경험을 개선하는 데 중점을 둡니다. 특히, 데이터베이스의 고유 제약 조건 위반과 관련된 동시성 문제를 효과적으로 처리하기 위한 에러 핸들링 로직을 강화하고, API 쿼리 파라미터의 타입 안전성을 높여 개발 편의성과 안정성을 확보했습니다. 또한, 특정 비즈니스 로직(예: 할 일 카테고리 삭제)의 유효성 검사를 개선하고, 모바일 앱에 더 명확한 에러 메시지를 제공하여 전반적인 시스템의 신뢰도를 높였습니다. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
전반적으로 훌륭한 PR입니다. Prisma P2002 에러에 대한 서비스 레벨 및 글로벌 핸들링을 추가하여 동시성 문제에 대한 방어 코드를 강화한 점이 인상적입니다. 특히 GlobalExceptionFilter를 통해 알려지지 않은 제약 조건에 대한 폴백 처리를 구현한 것은 시스템 안정성을 크게 높일 것입니다. GetCheersQueryDto와 GetNudgesQueryDto를 도입하여 수동 파싱 로직을 제거하고 타입 안전성을 개선한 부분도 좋은 리팩터링입니다.
AuthService의 에러 핸들링을 더 명확하게 하여 잠재적인 버그를 방지하는 내용의 추가 개선 제안을 리뷰 코멘트로 남겼습니다. 코드 병합 전에 확인해주시면 좋겠습니다.
P2002 catch 블록이 모든 unique constraint 위반을 이메일 중복으로 간주하던 문제 수정. error.meta.target에 email이 포함된 경우만 emailAlreadyRegistered를 던지고, 나머지는 GlobalExceptionFilter로 위임하도록 re-throw 처리.
📋 개요
Prisma unique constraint 위반(P2002) race condition 방어, Query DTO 타입 안전성 강화, TodoCategory 삭제 로직 개선, Mobile 에러 메시지 추가
🏷️ 변경 유형
feat- 새로운 기능 추가fix- 버그 수정📦 영향 범위
apps/api- NestJS 백엔드apps/mobile- Expo 모바일 앱packages/validators- Zod 스키마📝 변경 내용
1. GlobalExceptionFilter P2002 매핑 (
559885c)2. 서비스별 P2002 race condition 방어 (
3e08efe)auth.service: 이메일 중복 가입 → emailAlreadyRegisteredoauth.service: 계정 연결 중복 → provider별 alreadyLinked + 헬퍼 메서드 추출follow.service: 중복 친구 요청 → followRequestAlreadySentnotification.service: P2025(record not found)만 무시, 나머지 re-throw3. TodoCategory P2002 방어 및 삭제 로직 개선 (
c37dcd8)TODO_CATEGORY_0856→TODO_CATEGORY_0855(todoCategoryHasTodos)moveToCategoryId === categoryId자기 자신 이동 방지 (SYS_0002)4. Cheer/Nudge Query DTO 추가 (
4420ca9)@aido/validators에getCheersQuerySchema,getNudgesQuerySchema추가GetCheersQueryDto,GetNudgesQueryDto생성 (nestjs-zod)Number()파싱 제거 →@Query() query: DTO자동 파싱5. Mobile 에러 메시지 추가 (
f711e7f)USER_0611,TODO_0810,TODO_CATEGORY_0851~0856한국어 메시지 추가🧪 테스트
테스트 방법
테스트 결과
✅ 체크리스트
작성자 확인
pnpm check(Biome) 검사를 통과했습니다🔗 관련 이슈
Closes #118