zedkit
@zedtech/zedkit-server

Tell a Postgres conflict from a bug

@zedtech/zedkit-server — beta

beta

At a glance

  • Who: Developers mapping Postgres driver errors to HTTP responses.
  • What: Extract the Postgres error code so unique violations map to 409, not 500.
  • Use when: Around writes where a conflict is an expected outcome (signup, idempotent creates).
  • Avoid when: For query building or migrations — use your ORM or migration tool instead.
  • See also: Return uniform error bodies

Install

pnpm add @zedtech/zedkit-server

Latest: 0.1.2 (via changesets).

Example

Usage
import { pgErrorCode } from "@zedtech/zedkit-server";
try {
  await db.insert(users).values(row);
} catch (error) {
  if (pgErrorCode(error) === "23505") return conflict();
  throw error;
}

Wraps: (none)

On this page