MCPcopy Create free account
hub / github.com/blockmatic/basilic / getPgErrorCode

Function getPgErrorCode

apps/api/src/lib/db-errors.ts:2–7  ·  view source on GitHub ↗
(err: unknown)

Source from the content-addressed store, hash-verified

1/** Extract Postgres error code from Drizzle/Driver error (23505 = unique violation) */
2export function getPgErrorCode(err: unknown): string | undefined {
3 return (
4 (err as { cause?: { code?: string }; code?: string }).cause?.code ??
5 (err as { code?: string }).code
6 )
7}
8
9export function isUniqueViolation(err: unknown): boolean {
10 return getPgErrorCode(err) === '23505'

Callers 1

isUniqueViolationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected