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

Function tryClassifyConnectionError

src/utils/tool-handler-helpers.ts:89–109  ·  view source on GitHub ↗
(
  error: unknown,
  rawSourceId: string | undefined,
  displaySourceId: string
)

Source from the content-addressed store, hash-verified

87 * @param displaySourceId human-readable id used in the message + details
88 */
89export function tryClassifyConnectionError(
90 error: unknown,
91 rawSourceId: string | undefined,
92 displaySourceId: string
93): ReturnType<typeof createToolErrorResponse> | null {
94 // Defensive: getSourceConfig throws if the manager is uninitialized. Keep
95 // this helper as total as classifyConnectionError itself — never throw from
96 // within a caller's catch block.
97 let connectorType: ConnectorType | undefined;
98 try {
99 connectorType = ConnectorManager.getSourceConfig(rawSourceId)?.type;
100 } catch {
101 return null;
102 }
103 if (!connectorType) return null;
104 const classified = classifyConnectionError(error, connectorType, displaySourceId);
105 if (!classified) return null;
106 return createToolErrorResponse(classified.message, classified.code, {
107 source_id: displaySourceId,
108 });
109}
110
111/**
112 * Higher-order function to wrap tool handlers with automatic request tracking

Calls 3

classifyConnectionErrorFunction · 0.85
createToolErrorResponseFunction · 0.85
getSourceConfigMethod · 0.80

Tested by

no test coverage detected