( cause: unknown, message: string, operation: string )
| 924 | } |
| 925 | |
| 926 | const classifyError = ( |
| 927 | cause: unknown, |
| 928 | message: string, |
| 929 | operation: string |
| 930 | ) => { |
| 931 | const props = { cause, message, operation } |
| 932 | const code = pgCodeFromCause(cause) |
| 933 | if (code !== undefined) { |
| 934 | if (code.startsWith("08")) { |
| 935 | return new ConnectionError(props) |
| 936 | } |
| 937 | if (code.startsWith("28")) { |
| 938 | return new AuthenticationError(props) |
| 939 | } |
| 940 | if (code === "42501") { |
| 941 | return new AuthorizationError(props) |
| 942 | } |
| 943 | if (code.startsWith("42")) { |
| 944 | return new SqlSyntaxError(props) |
| 945 | } |
| 946 | if (code === "23505") { |
| 947 | return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) }) |
| 948 | } |
| 949 | if (code.startsWith("23")) { |
| 950 | return new ConstraintError(props) |
| 951 | } |
| 952 | if (code === "40P01") { |
| 953 | return new DeadlockError(props) |
| 954 | } |
| 955 | if (code === "40001") { |
| 956 | return new SerializationError(props) |
| 957 | } |
| 958 | if (code === "55P03") { |
| 959 | return new LockTimeoutError(props) |
| 960 | } |
| 961 | if (code === "57014") { |
| 962 | return new StatementTimeoutError(props) |
| 963 | } |
| 964 | } |
| 965 | return new UnknownError(props) |
| 966 | } |
no test coverage detected