| 267 | // letting `res.json()` throw an unclassified SyntaxError, so void-returning callers |
| 268 | // (revoke, stopTask, …) stay safe when a server replies with No Content. |
| 269 | async function parseJsonBody<T>(res: Response): Promise<T> { |
| 270 | if (res.status === 204 || res.status === 205) |
| 271 | return undefined as T |
| 272 | const text = await res.text() |
| 273 | return (text === '' ? undefined : JSON.parse(text)) as T |
| 274 | } |
| 275 | |
| 276 | export function createHttpClient(opts: ClientOptions): HttpClient { |
| 277 | const state = compileState(opts) |