From 655ec610fcce8dd7748f10772d520bdff4f7c78e Mon Sep 17 00:00:00 2001 From: Arne Rief Date: Fri, 19 Dec 2025 20:03:03 +0100 Subject: Basic setup & login --- backend/src/utils/dbErrorCheck.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 backend/src/utils/dbErrorCheck.ts (limited to 'backend/src/utils') diff --git a/backend/src/utils/dbErrorCheck.ts b/backend/src/utils/dbErrorCheck.ts new file mode 100644 index 0000000..c5c6415 --- /dev/null +++ b/backend/src/utils/dbErrorCheck.ts @@ -0,0 +1,16 @@ +import type { PostgresError } from "../types/database.js"; + +export function isPostgresError(error: unknown): error is PostgresError { + return ( + error instanceof Error && + "code" in error && + typeof (error as PostgresError).code === "string" + ); +} + +export const PostgresErrorCodes = { + UNIQUE_VIOLATION: "23505", + FOREIGN_KEY_VIOLATION: "23503", + NOT_NULL_VIOLATION: "23502", + CHECK_VIOLATION: "23514", +}; -- cgit v1.2.3