( cause: unknown, message: string, operation: string, fallback: "connection" | "unknown" = "unknown" )
| 102 | } |
| 103 | |
| 104 | const classifyError = ( |
| 105 | cause: unknown, |
| 106 | message: string, |
| 107 | operation: string, |
| 108 | fallback: "connection" | "unknown" = "unknown" |
| 109 | ) => { |
| 110 | const props = { cause, message, operation } |
| 111 | const number = mssqlNumberFromCause(cause) |
| 112 | if (number !== undefined) { |
| 113 | if (mssqlConnectionErrorCodes.has(number)) { |
| 114 | return new ConnectionError(props) |
| 115 | } |
| 116 | if (mssqlAuthenticationErrorCodes.has(number)) { |
| 117 | return new AuthenticationError(props) |
| 118 | } |
| 119 | if (mssqlAuthorizationErrorCodes.has(number)) { |
| 120 | return new AuthorizationError(props) |
| 121 | } |
| 122 | if (mssqlSyntaxErrorCodes.has(number)) { |
| 123 | return new SqlSyntaxError(props) |
| 124 | } |
| 125 | if (number === 2601 || number === 2627) { |
| 126 | return new UniqueViolation({ ...props, constraint: mssqlUniqueViolationConstraintFromCause(number, cause) }) |
| 127 | } |
| 128 | if (mssqlConstraintErrorCodes.has(number)) { |
| 129 | return new ConstraintError(props) |
| 130 | } |
| 131 | if (number === 1205) { |
| 132 | return new DeadlockError(props) |
| 133 | } |
| 134 | if (number === 3960) { |
| 135 | return new SerializationError(props) |
| 136 | } |
| 137 | if (number === 1222) { |
| 138 | return new LockTimeoutError(props) |
| 139 | } |
| 140 | } |
| 141 | return fallback === "connection" ? new ConnectionError(props) : new UnknownError(props) |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Runtime type identifier used to mark `MssqlClient` values. |
no test coverage detected