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