{"record":{"id":"2b2911eb4d84f44e","repo":"affaan-m/ECC","slug":"email-already-registered","errorCode":null,"errorMessage":"Email already registered","messagePattern":"Email already registered","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"skills/fastapi-patterns/SKILL.md","lineNumber":248,"sourceCode":"# app/routers/users.py\nfrom typing import Annotated\nfrom fastapi import APIRouter, HTTPException, Query, status\nfrom fastapi.security import OAuth2PasswordRequestForm\n\nfrom app.dependencies import ActiveUserDep, DbDep\nfrom app.schemas.user import UserCreate, UserResponse, UserUpdate, UserListResponse\nfrom app.services.user_service import DuplicateUserError, UserService\n\nrouter = APIRouter()\n\n\n@router.post(\"/\", response_model=UserResponse, status_code=status.HTTP_201_CREATED)\nasync def create_user(payload: UserCreate, db: DbDep) -> UserResponse:\n    service = UserService(db)\n    try:\n        return await service.create(payload)\n    except DuplicateUserError:\n        raise HTTPException(status_code=400, detail=\"Email already registered\")\n\n\n@router.get(\"/me\", response_model=UserResponse)\nasync def get_me(current_user: ActiveUserDep) -> UserResponse:\n    return current_user\n\n\n@router.get(\"/\", response_model=UserListResponse)\nasync def list_users(\n    db: DbDep,\n    current_user: ActiveUserDep,\n    skip: Annotated[int, Query(ge=0)] = 0,\n    limit: Annotated[int, Query(ge=1, le=100)] = 20,\n) -> UserListResponse:\n    service = UserService(db)\n    users, total = await service.list(skip=skip, limit=limit)\n    return UserListResponse(total=total, items=users)\n","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/affaan-m/ECC/blob/d8409a4b0813771235555e32e3d8046a73988bfa/skills/fastapi-patterns/SKILL.md#L230-L266","documentation":"Illustrative handler from the fastapi-patterns skill: UserService raised DuplicateUserError while creating/updating a user, which the router translates into an HTTP 400 with this detail. The email in the payload already exists in the database.","triggerScenarios":"Thrown at skills/fastapi-patterns/SKILL.md:248 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Enforce uniqueness with a DB constraint in addition to the service check","Return 409 Conflict for duplicate resources","Suggest login/password-reset when the email is already registered"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d8409a4b0813771235555e32e3d8046a73988bfa","analyzedAt":"2026-08-26T12:15:34.022Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}