* Extracts a message string from a response data payload
(data: unknown)
| 359 | * Extracts a message string from a response data payload |
| 360 | */ |
| 361 | protected extractFromData(data: unknown): string | undefined { |
| 362 | if (typeof data === 'string') { |
| 363 | return data; |
| 364 | } |
| 365 | |
| 366 | if (typeof data === 'object' && data !== null) { |
| 367 | const obj = data as Record<string, unknown>; |
| 368 | |
| 369 | if (obj.error) { |
| 370 | if (typeof obj.error === 'string') { |
| 371 | return obj.error; |
| 372 | } |
| 373 | if (typeof obj.error === 'object' && obj.error !== null && 'message' in obj.error) { |
| 374 | return String((obj.error as Record<string, unknown>).message); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (typeof obj.message === 'string') { |
| 379 | return obj.message; |
| 380 | } |
| 381 | |
| 382 | if (typeof obj.errorMsg === 'string') { |
| 383 | return obj.errorMsg; |
| 384 | } |
| 385 | |
| 386 | try { |
| 387 | return JSON.stringify(data); |
| 388 | } catch { |
| 389 | return undefined; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | return undefined; |
| 394 | } |
| 395 | } |