Spaces:
Paused
Paused
Download packages/core/src/db/errors.ts from f4b404/aiostreams: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/f4b404/aiostreams/resolve/main/packages/core/src/db/errors.ts
- Command line
-
hf download hf://spaces/f4b404/aiostreams/packages/core/src/db/errors.ts
-
curl -L -o errors.ts https://huggingface.co/spaces/f4b404/aiostreams/resolve/main/packages/core/src/db/errors.ts
1.11 kB
| export type DbErrorKind = | |
| | 'unique-violation' | |
| | 'fk-violation' | |
| | 'not-found' | |
| | 'connection' | |
| | 'unknown'; | |
| export class DbError extends Error { | |
| readonly kind: DbErrorKind; | |
| readonly cause?: unknown; | |
| constructor(kind: DbErrorKind, message: string, cause?: unknown) { | |
| super(message); | |
| this.name = 'DbError'; | |
| this.kind = kind; | |
| this.cause = cause; | |
| } | |
| } | |
| export function classifyPgError(err: unknown): DbErrorKind { | |
| const code = (err as { code?: string } | undefined)?.code; | |
| if (code === '23505') return 'unique-violation'; | |
| if (code === '23503') return 'fk-violation'; | |
| if ( | |
| code === 'ECONNREFUSED' || | |
| code === 'ECONNRESET' || | |
| code === 'ETIMEDOUT' | |
| ) { | |
| return 'connection'; | |
| } | |
| return 'unknown'; | |
| } | |
| export function classifySqliteError(err: unknown): DbErrorKind { | |
| const code = (err as { code?: string } | undefined)?.code; | |
| if ( | |
| code === 'SQLITE_CONSTRAINT_UNIQUE' || | |
| code === 'SQLITE_CONSTRAINT_PRIMARYKEY' | |
| ) { | |
| return 'unique-violation'; | |
| } | |
| if (code === 'SQLITE_CONSTRAINT_FOREIGNKEY') return 'fk-violation'; | |
| return 'unknown'; | |
| } | |