( cause: unknown, message: string, operation: string, fallback: "connection" | "unknown" = "unknown" )
| 59 | const clickhouseSyntaxErrorCodes = new Set([36, 60, 62, 242]) |
| 60 | |
| 61 | const classifyError = ( |
| 62 | cause: unknown, |
| 63 | message: string, |
| 64 | operation: string, |
| 65 | fallback: "connection" | "unknown" = "unknown" |
| 66 | ) => { |
| 67 | const props = { cause, message, operation } |
| 68 | const code = clickhouseCodeFromCause(cause) |
| 69 | if (code !== undefined) { |
| 70 | if (code === 516) { |
| 71 | return new AuthenticationError(props) |
| 72 | } |
| 73 | if (code === 497) { |
| 74 | return new AuthorizationError(props) |
| 75 | } |
| 76 | if (clickhouseSyntaxErrorCodes.has(code)) { |
| 77 | return new SqlSyntaxError(props) |
| 78 | } |
| 79 | if (code === 159 || code === 469) { |
| 80 | return new StatementTimeoutError(props) |
| 81 | } |
| 82 | } |
| 83 | return fallback === "connection" ? new ConnectionError(props) : new UnknownError(props) |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Unique runtime identifier used to tag `ClickhouseClient` values. |
no test coverage detected