First attempt checked err.code, which is undefined — drizzle-orm wraps the raw pg error (the one that actually has .code = '23505' for a unique violation) in .cause. Live-tested and caught before assuming the fix worked from code review alone. Now checks err.cause?.code first, falls back to err.code. Verified: first add 201, duplicate add 409 "Member is already on this team" instead of 500. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0143yYvjesjHndBACoweyK67