( url: string, init: RequestInit )
| 122 | |
| 123 | /** Wraps `fetch` for OAuth-shaped JSON; throws on non-2xx. */ |
| 124 | export const fetchJson = async ( |
| 125 | url: string, |
| 126 | init: RequestInit |
| 127 | ): Promise<unknown> => { |
| 128 | /* |
| 129 | * Bounded budget — these calls sit on the OAuth callback request |
| 130 | * path; a hung IdP token endpoint must not pin the handler. Callers |
| 131 | * may override via init.signal. |
| 132 | */ |
| 133 | const res = await fetch(url, { |
| 134 | signal: AbortSignal.timeout(OAUTH_FETCH_TIMEOUT_MS), |
| 135 | ...init, |
| 136 | }); |
| 137 | |
| 138 | if (!res.ok) { |
| 139 | const body = await res.text(); |
| 140 | |
| 141 | throw ApiErrors.externalService( |
| 142 | `HTTP ${String(res.status)} from ${url}: ${body}` |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | return res.json(); |
| 147 | }; |
| 148 | |
| 149 | /* |
| 150 | * --------------------------------------------------------------------------- |
no outgoing calls
no test coverage detected