(response: Response)
| 15 | * Parses a Brex API response body, throwing a descriptive error for non-2xx responses. |
| 16 | */ |
| 17 | export async function parseBrexJson(response: Response) { |
| 18 | if (!response.ok) { |
| 19 | const text = await response.text() |
| 20 | let message = text |
| 21 | try { |
| 22 | const parsed = JSON.parse(text) |
| 23 | message = parsed.message ?? text |
| 24 | } catch { |
| 25 | message = text |
| 26 | } |
| 27 | throw new Error(`Brex API error (${response.status}): ${message}`) |
| 28 | } |
| 29 | return response.json() |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Appends a comma-separated value as repeated query parameters (Brex array syntax). |
no test coverage detected