mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
The Prisma unique-constraint (P2002) narrowing predicate had been hand-copied into five call sites. Fold them into a single isP2002 in src/lib/prisma-errors.ts and import it everywhere (the two step-drain sites keep their local isUniqueConstraintViolation name via an import alias). Behaviour-identical; one place to chase a future P2002-semantics change instead of five. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
25 lines
899 B
TypeScript
25 lines
899 B
TypeScript
/**
|
|
* Shared Prisma error narrowing helpers.
|
|
*
|
|
* The P2002 (unique-constraint violation) predicate was hand-copied into
|
|
* five call sites (rollup persist, intake-slot dedup, slot upsert, legacy
|
|
* step consolidation, dense-intraday retention). v1.11.2 folds them into
|
|
* this single helper so a future change to the P2002 semantics has one
|
|
* place to live instead of five.
|
|
*
|
|
* Deliberately structural (`typeof === "object"` + `"code" in err` +
|
|
* `code === "P2002"`) rather than `instanceof Prisma.PrismaClientKnownRequestError`
|
|
* so it survives client-bundling quirks while staying specific to the
|
|
* unique-constraint code.
|
|
*/
|
|
|
|
/** Narrow a thrown Prisma error to the P2002 unique-constraint code. */
|
|
export function isP2002(err: unknown): boolean {
|
|
return (
|
|
typeof err === "object" &&
|
|
err !== null &&
|
|
"code" in err &&
|
|
(err as { code: unknown }).code === "P2002"
|
|
);
|
|
}
|