( error: unknown, rawSourceId: string | undefined, displaySourceId: string )
| 87 | * @param displaySourceId human-readable id used in the message + details |
| 88 | */ |
| 89 | export 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 |
no test coverage detected