diff options
| author | Arne Rief <riearn@proton.me> | 2025-12-19 20:03:03 +0100 |
|---|---|---|
| committer | Arne Rief <riearn@proton.me> | 2025-12-19 20:03:03 +0100 |
| commit | 655ec610fcce8dd7748f10772d520bdff4f7c78e (patch) | |
| tree | 35b79f30d2cb5aea88cf76ce27f480da93cefd32 /backend/src/utils | |
Basic setup & login
Diffstat (limited to 'backend/src/utils')
| -rw-r--r-- | backend/src/utils/dbErrorCheck.ts | 16 |
1 files changed, 16 insertions, 0 deletions
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", +}; |
