fix(server): map unique-violation on register to 409 UsernameTaken #140

Closed
opened 2026-07-07 03:06:04 +00:00 by funman300 · 0 comments
Owner

Review finding L2 (2026-07-06). register (auth.rs) does SELECT-then-INSERT; the username UNIQUE constraint makes concurrent duplicate registration safe, but the loser gets a raw database error (500) instead of UsernameTaken. Fix: inspect the sqlx error for a unique-constraint violation and map it to the 409 path (keep the friendly pre-check for the common case).

Principle: let the database constraint be the arbiter of uniqueness; the application maps its violation to a domain error rather than trying to pre-empt it racily.

🤖 Generated with Claude Code

Review finding L2 (2026-07-06). `register` (auth.rs) does SELECT-then-INSERT; the `username UNIQUE` constraint makes concurrent duplicate registration safe, but the loser gets a raw database error (500) instead of `UsernameTaken`. Fix: inspect the sqlx error for a unique-constraint violation and map it to the 409 path (keep the friendly pre-check for the common case). **Principle:** let the database constraint be the arbiter of uniqueness; the application maps its violation to a domain error rather than trying to pre-empt it racily. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/Ferrous-Solitaire#140