* Extracts error message from various error formats
(error: unknown)
| 270 | * Extracts error message from various error formats |
| 271 | */ |
| 272 | protected extractErrorMessage(error: unknown): string { |
| 273 | // Axios error with response data |
| 274 | if (axios.isAxiosError(error) && error.response?.data) { |
| 275 | const data: unknown = error.response.data; |
| 276 | |
| 277 | // Try various common error message paths |
| 278 | if (typeof data === 'string') { |
| 279 | return data; |
| 280 | } |
| 281 | |
| 282 | if (typeof data === 'object' && data !== null) { |
| 283 | const obj = data as Record<string, unknown>; |
| 284 | |
| 285 | if (obj.error) { |
| 286 | if (typeof obj.error === 'string') { |
| 287 | return obj.error; |
| 288 | } |
| 289 | if (typeof obj.error === 'object' && obj.error !== null && 'message' in obj.error) { |
| 290 | return String((obj.error as Record<string, unknown>).message); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if (typeof obj.message === 'string') { |
| 295 | return obj.message; |
| 296 | } |
| 297 | |
| 298 | if (typeof obj.errorMsg === 'string') { |
| 299 | return obj.errorMsg; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // Fallback to stringified data |
| 304 | return JSON.stringify(data); |
| 305 | } |
| 306 | |
| 307 | // Plain object with status and data (e.g., Polymarket clob-client errors) |
| 308 | // These aren't AxiosError instances but have similar structure |
| 309 | if (isPlainErrorObject(error)) { |
| 310 | const data: unknown = error.data; |
| 311 | |
| 312 | if (data) { |
| 313 | const extracted = this.extractFromData(data); |
| 314 | if (extracted) { |
| 315 | return extracted; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // Check for message at top level |
| 320 | if (error.message && typeof error.message === 'string') { |
| 321 | return error.message; |
| 322 | } |
| 323 | |
| 324 | if (error.statusText && typeof error.statusText === 'string') { |
| 325 | return error.statusText; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Standard Error object - check for attached response data from third-party SDKs |
no test coverage detected