* Implementation for logError - writes error to debug log and file.
(error: Error)
| 151 | * Implementation for logError - writes error to debug log and file. |
| 152 | */ |
| 153 | function logErrorImpl(error: Error): void { |
| 154 | const errorStr = error.stack || error.message |
| 155 | |
| 156 | // Enrich axios errors with request URL, status, and server message for debugging |
| 157 | let context = '' |
| 158 | if (axios.isAxiosError(error) && error.config?.url) { |
| 159 | const parts = [`url=${error.config.url}`] |
| 160 | if (error.response?.status !== undefined) { |
| 161 | parts.push(`status=${error.response.status}`) |
| 162 | } |
| 163 | const serverMessage = extractServerMessage(error.response?.data) |
| 164 | if (serverMessage) { |
| 165 | parts.push(`body=${serverMessage}`) |
| 166 | } |
| 167 | context = `[${parts.join(',')}] ` |
| 168 | } |
| 169 | |
| 170 | logForDebugging(`${error.name}: ${context}${errorStr}`, { level: 'error' }) |
| 171 | |
| 172 | appendToLog(getErrorsPath(), { |
| 173 | error: `${context}${errorStr}`, |
| 174 | }) |
| 175 | |
| 176 | // Also report to Sentry (no-op if not initialized) |
| 177 | captureException(error) |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Implementation for logMCPError - writes MCP error to debug log and file. |
no test coverage detected