Skip to content

Conversation

@jameswhite-cmd
Copy link

What I changed

  • Backend

    • Added a ConflictError model to app/models.py to document a consistent error response shape used for conflicts: {"error":"conflict","field":"email","message":"Already in use"}.
    • Modified the create_user and register_user handlers in app/api/routes/users.py to defensively return a 409 JSONResponse when an existing email is detected, and declared the 409 response in the route OpenAPI metadata (responses={409: {"model": ConflictError}}).
    • This provides a stable, documented API surface for duplicate email/username conflicts.
  • Tests

    • Updated backend unit tests (backend/tests/api/routes/test_users.py) to expect HTTP 409 and the new JSON error body for duplicate user creation / signup cases.
  • Frontend

    • Updated signup flow (frontend/src/routes/signup.tsx) to import and handle the ApiError shape, map an API 409 conflict to an inline form error via setError(field), and fall back to the generic handleError for other failures.
    • Updated the Playwright test (frontend/tests/sign-up.spec.ts) to assert the inline error text "Already in use" is visible when attempting to sign up with an existing email.

Why

  • The API now consistently communicates duplicate resource conflicts with HTTP 409 and a structured JSON body so frontend clients can map the error directly to form fields.
  • The OpenAPI model (ConflictError) documents the error response so clients and consumers can rely on the shape.
  • Tests were updated to reflect the new behavior and ensure regression coverage.

Files changed (high level)

  • backend/app/api/routes/users.py: return JSONResponse 409 for duplicate email, add responses metadata
  • backend/app/models.py: add ConflictError model
  • backend/tests/api/routes/test_users.py: updated assertions to expect 409 and new body
  • frontend/src/routes/signup.tsx: map 409 conflict to setError for inline field error
  • frontend/tests/sign-up.spec.ts: expect inline "Already in use" message

Notes

  • This PR focuses on returning a consistent conflict response and wiring it through frontend handling and tests. Database unique constraints and any additional defensive checks should be verified/added in subsequent commits if not already present in the DB schema migrations.

This pull request was co-created with Cosine Genie

Original Task: full-stack-demo/uqvx8xon2xmt
Author: James White

…or; map frontend signup to show inline field error

Co-authored-by: Genie <[email protected]>
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