| 160 | * Throw-on-error: bridges openapi-fetch's `{ data, error, response }` shape |
| 161 | * to TanStack Query's "throw to signal failure" expectation. Runs AFTER |
| 162 | * `tokenRefresh` so a transparent retry has a chance first. |
| 163 | * ---------------------------------------------------------------------------- |
| 164 | */ |
| 165 | |
| 166 | /* |
| 167 | * The api always envelopes errors as `{ success: false, error: { code, |
| 168 | * message, fieldErrors?, timestamp } }`. The flat `IApiErrorBody` shape |
| 169 | * (no envelope) is retained as a fallback for any non-enveloped 4xx that |
| 170 | * slips through, opaque proxy errors, 502s from edge, etc., so the |
| 171 | * caller always sees a usable code/message instead of `undefined`. |
| 172 | */ |
| 173 | /* Keep only string-valued entries, fieldErrors is `Record<string, string>`. */ |
| 174 | const toStringRecord = (value: unknown): Record<string, string> | undefined => { |
| 175 | if (typeof value !== "object" || value === null) { |
| 176 | return undefined; |
| 177 | } |
| 178 | |
| 179 | const out: Record<string, string> = {}; |