fix(server): map unique-violation on register to 409 UsernameTaken #140
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Review finding L2 (2026-07-06).
register(auth.rs) does SELECT-then-INSERT; theusername UNIQUEconstraint makes concurrent duplicate registration safe, but the loser gets a raw database error (500) instead ofUsernameTaken. 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