( cause: unknown, message: string, operation: string )
| 471 | } |
| 472 | |
| 473 | const classifyError = ( |
| 474 | cause: unknown, |
| 475 | message: string, |
| 476 | operation: string |
| 477 | ) => { |
| 478 | const props = { cause, message, operation } |
| 479 | const code = pgCodeFromCause(cause) |
| 480 | if (code !== undefined) { |
| 481 | if (code.startsWith("08")) { |
| 482 | return new ConnectionError(props) |
| 483 | } |
| 484 | if (code.startsWith("28")) { |
| 485 | return new AuthenticationError(props) |
| 486 | } |
| 487 | if (code === "42501") { |
| 488 | return new AuthorizationError(props) |
| 489 | } |
| 490 | if (code.startsWith("42")) { |
| 491 | return new SqlSyntaxError(props) |
| 492 | } |
| 493 | if (code === "23505") { |
| 494 | return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) }) |
| 495 | } |
| 496 | if (code.startsWith("23")) { |
| 497 | return new ConstraintError(props) |
| 498 | } |
| 499 | if (code === "40P01") { |
| 500 | return new DeadlockError(props) |
| 501 | } |
| 502 | if (code === "40001") { |
| 503 | return new SerializationError(props) |
| 504 | } |
| 505 | if (code === "55P03") { |
| 506 | return new LockTimeoutError(props) |
| 507 | } |
| 508 | if (code === "57014") { |
| 509 | return new StatementTimeoutError(props) |
| 510 | } |
| 511 | } |
| 512 | return new UnknownError(props) |
| 513 | } |
no test coverage detected