| 127 | } |
| 128 | |
| 129 | function extractServerMessage(data: unknown): string | undefined { |
| 130 | if (typeof data === 'string') { |
| 131 | return data |
| 132 | } |
| 133 | if (data && typeof data === 'object') { |
| 134 | const obj = data as Record<string, unknown> |
| 135 | if (typeof obj.message === 'string') { |
| 136 | return obj.message |
| 137 | } |
| 138 | if ( |
| 139 | typeof obj.error === 'object' && |
| 140 | obj.error && |
| 141 | 'message' in obj.error && |
| 142 | typeof (obj.error as Record<string, unknown>).message === 'string' |
| 143 | ) { |
| 144 | return (obj.error as Record<string, unknown>).message as string |
| 145 | } |
| 146 | } |
| 147 | return undefined |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Implementation for logError - writes error to debug log and file. |