(raw: unknown)
| 209 | }; |
| 210 | |
| 211 | const extractApiErrorBody = (raw: unknown): IApiErrorBody => { |
| 212 | if (typeof raw !== "object" || raw === null) { |
| 213 | return { message: "Unknown error" }; |
| 214 | } |
| 215 | |
| 216 | if ("error" in raw) { |
| 217 | const nested: unknown = raw.error; |
| 218 | |
| 219 | if (typeof nested === "object" && nested !== null) { |
| 220 | return toErrorBody(nested); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return toErrorBody(raw); |
| 225 | }; |
| 226 | |
| 227 | const throwOnError: Middleware = { |
| 228 | onResponse: async ({ response }) => { |