( cause: unknown, message: string, operation: string )
| 497 | } |
| 498 | |
| 499 | const classifyError = ( |
| 500 | cause: unknown, |
| 501 | message: string, |
| 502 | operation: string |
| 503 | ) => { |
| 504 | const props = { cause, message, operation } |
| 505 | const code = pgCodeFromCause(cause) |
| 506 | if (code !== undefined) { |
| 507 | if (code.startsWith("08")) { |
| 508 | return new ConnectionError(props) |
| 509 | } |
| 510 | if (code.startsWith("28")) { |
| 511 | return new AuthenticationError(props) |
| 512 | } |
| 513 | if (code === "42501") { |
| 514 | return new AuthorizationError(props) |
| 515 | } |
| 516 | if (code.startsWith("42")) { |
| 517 | return new SqlSyntaxError(props) |
| 518 | } |
| 519 | if (code === "23505") { |
| 520 | return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) }) |
| 521 | } |
| 522 | if (code.startsWith("23")) { |
| 523 | return new ConstraintError(props) |
| 524 | } |
| 525 | if (code === "40P01") { |
| 526 | return new DeadlockError(props) |
| 527 | } |
| 528 | if (code === "40001") { |
| 529 | return new SerializationError(props) |
| 530 | } |
| 531 | if (code === "55P03") { |
| 532 | return new LockTimeoutError(props) |
| 533 | } |
| 534 | if (code === "57014") { |
| 535 | return new StatementTimeoutError(props) |
| 536 | } |
| 537 | } |
| 538 | return new UnknownError(props) |
| 539 | } |
no test coverage detected