Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions db/errors/postgres-error-constants-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CLIENT_FAULT_POSTGRES_ERROR_CLASSES,
POSTGRES_ERROR_CLASS_TO_TITLE_MAP,
POSTGRES_ERROR_CODE_TO_MESSAGE_MAP,
POSTGRES_ERROR_SEVERITIES,
Expand All @@ -12,6 +13,9 @@ export const postgresErrorCodeParser = zodEnumFromObjKeys(
POSTGRES_ERROR_CODE_TO_MESSAGE_MAP,
);

export const clientFaultPostgresErrorClassParser = zodEnumFromObjKeys(
POSTGRES_ERROR_CLASS_TO_TITLE_MAP,
).extract(CLIENT_FAULT_POSTGRES_ERROR_CLASSES);
export const publicPostgresErrorClassParser = zodEnumFromObjKeys(
POSTGRES_ERROR_CLASS_TO_TITLE_MAP,
).extract(PUBLIC_POSTGRES_ERROR_CLASSES);
Expand Down
3 changes: 2 additions & 1 deletion db/errors/postgres-error-constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const PUBLIC_POSTGRES_ERROR_CLASSES = ["22", "23"] as const;
export const PUBLIC_POSTGRES_ERROR_CLASSES = ["02", "22", "23"] as const;
export const CLIENT_FAULT_POSTGRES_ERROR_CLASSES = ["02", "22", "23"] as const;

// from https://www.postgresql.org/docs/9.3/protocol-error-fields.html
export const POSTGRES_ERROR_SEVERITIES = ["ERROR", "FATAL", "PANIC"] as const;
Expand Down
7 changes: 7 additions & 0 deletions db/errors/postgres-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
clientFaultPostgresErrorClassParser,
generatePostgresErrorCodeInfo,
postgresErrorCodeParser,
postgresSeverityParser,
Expand Down Expand Up @@ -53,6 +54,12 @@ export const postgresErrorParser = z

export type ParsedPostgresError = z.infer<typeof postgresErrorParser>;

export function isPostgresErrorClientFault(
databaseError: ParsedPostgresError,
): boolean {
const codeInfo = generatePostgresErrorCodeInfo(databaseError.code);
return clientFaultPostgresErrorClassParser.safeParse(codeInfo.class).success;
}
export function getDatabaseErrorPublicMessage(
databaseError: ParsedPostgresError,
): string {
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,36 @@
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.33.0",
"drizzle-seed": "^0.3.1",
"drizzle-zod": "^0.5.1",
"express": "^4.21.1",
"pg": "^8.13.0",
"express": "^4.21.2",
"express-zod-safe": "^1.3.3",
"pg": "^8.14.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1",
"validator": "^13.12.0",
"zod": "^3.23.8",
"validator": "^13.15.0",
"zod": "^3.24.2",
"zod-openapi": "^3.3.0",
"zod-validation-error": "^3.4.0"
},
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^22.7.8",
"@types/pg": "^8.11.10",
"@types/supertest": "^6.0.2",
"@types/node": "^22.14.0",
"@types/pg": "^8.11.11",
"@types/supertest": "^6.0.3",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.7",
"@types/validator": "^13.12.2",
"@types/swagger-ui-express": "^4.1.8",
"@types/validator": "^13.12.3",
"drizzle-kit": "^0.24.2",
"supertest": "^7.0.0",
"tsc-alias": "^1.8.10",
"tsx": "^4.19.1",
"typescript": "^5.6.3",
"yaml": "^2.6.0"
"supertest": "^7.1.0",
"tsc-alias": "^1.8.13",
"tsx": "^4.19.3",
"typescript": "^5.8.2",
"yaml": "^2.7.1"
},
"packageManager": "pnpm@10.6.4+sha512.da3d715bfd22a9a105e6e8088cfc7826699332ded60c423b14ec613a185f1602206702ff0fe4c438cb15c979081ce4cb02568e364b15174503a63c7a8e2a5f6c"
"packageManager": "pnpm@10.6.5+sha512.cdf928fca20832cd59ec53826492b7dc25dc524d4370b6b4adbf65803d32efaa6c1c88147c0ae4e8d579a6c9eec715757b50d4fa35eea179d868eada4ed043af"
}
Loading