| 35 | } |
| 36 | |
| 37 | export const classifySqlState = ( |
| 38 | code: string | undefined, |
| 39 | constraint: unknown, |
| 40 | props: ErrorProps |
| 41 | ): SqlErrorReason => { |
| 42 | if (code !== undefined) { |
| 43 | if (code.startsWith("08")) { |
| 44 | return new ConnectionError(props) |
| 45 | } |
| 46 | if (code.startsWith("28")) { |
| 47 | return new AuthenticationError(props) |
| 48 | } |
| 49 | if (code === "42501") { |
| 50 | return new AuthorizationError(props) |
| 51 | } |
| 52 | if (code.startsWith("42")) { |
| 53 | return new SqlSyntaxError(props) |
| 54 | } |
| 55 | if (code === "23505") { |
| 56 | return new UniqueViolation({ ...props, constraint: normalizeConstraint(constraint) }) |
| 57 | } |
| 58 | if (code.startsWith("23")) { |
| 59 | return new ConstraintError(props) |
| 60 | } |
| 61 | if (code === "40P01") { |
| 62 | return new DeadlockError(props) |
| 63 | } |
| 64 | if (code === "40001") { |
| 65 | return new SerializationError(props) |
| 66 | } |
| 67 | if (code === "55P03") { |
| 68 | return new LockTimeoutError(props) |
| 69 | } |
| 70 | if (code === "57014") { |
| 71 | return new StatementTimeoutError(props) |
| 72 | } |
| 73 | } |
| 74 | return new UnknownError(props) |
| 75 | } |