Skip to content

fix: lobby creation 500 — P2002 not caught when meta.target is null (Prisma 7) #596

@KovalDenys1

Description

@KovalDenys1

Bug

Creating a lobby sometimes throws a 500 error instead of retrying with a new code:

Invalid `prisma.lobbies.create()` invocation
Unique constraint failed on the fields: (`code`)

Root Cause

isLobbyCodeConflict() in app/api/lobby/route.ts checks meta.target to confirm the P2002 is for the code field. In Prisma 7, meta.target can be null/undefined even on a genuine code collision, causing the function to return false and the API to throw instead of retry.

Fix

Add fallback: when prismaCode === 'P2002' and target is absent, check the error message string for "unique constraint"" + "code"; if that also fails, return true (any P2002 on lobbies.create must be the code field).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions