MCPcopy Index your code
hub / github.com/bytebase/dbhub / classifyConnectionError

Function classifyConnectionError

src/utils/error-classifier.ts:60–90  ·  view source on GitHub ↗
(
  error: unknown,
  connectorType: ConnectorType,
  sourceId: string
)

Source from the content-addressed store, hash-verified

58 * Pure; never throws.
59 */
60export 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}

Callers 2

Calls 3

tunnelMessageFunction · 0.85
unreachableMessageFunction · 0.85
authMessageFunction · 0.85

Tested by

no test coverage detected