( error: unknown, connectorType: ConnectorType, sourceId: string )
| 58 | * Pure; never throws. |
| 59 | */ |
| 60 | export function classifyConnectionError( |
| 61 | error: unknown, |
| 62 | connectorType: ConnectorType, |
| 63 | sourceId: string |
| 64 | ): { code: ConnectionErrorCode; message: string } | null { |
| 65 | if (!error || typeof error !== "object") { |
| 66 | return null; |
| 67 | } |
| 68 | const err = error as Record<string, unknown>; |
| 69 | |
| 70 | // Tunnel marker wins over the underlying network code. |
| 71 | if (err[TUNNEL_ERROR_MARKER] === true) { |
| 72 | return { code: "TUNNEL_FAILED", message: tunnelMessage(sourceId) }; |
| 73 | } |
| 74 | |
| 75 | const code = err.code; |
| 76 | if (typeof code === "string" && NETWORK_CODES.has(code)) { |
| 77 | return { code: "SOURCE_UNREACHABLE", message: unreachableMessage(sourceId) }; |
| 78 | } |
| 79 | |
| 80 | const authCodes = AUTH_CODES[connectorType]; |
| 81 | const errno = err.errno; |
| 82 | if ( |
| 83 | (typeof code === "string" && authCodes.includes(code)) || |
| 84 | (typeof errno === "number" && authCodes.includes(errno)) |
| 85 | ) { |
| 86 | return { code: "AUTH_FAILED", message: authMessage(sourceId) }; |
| 87 | } |
| 88 | |
| 89 | return null; |
| 90 | } |
no test coverage detected