(url, body)
| 644 | } |
| 645 | |
| 646 | async function fetchJson(url, body) { |
| 647 | let response; |
| 648 | try { |
| 649 | response = await fetch(url, { |
| 650 | body: JSON.stringify(body), |
| 651 | headers: { "content-type": "application/json" }, |
| 652 | method: "POST", |
| 653 | signal: AbortSignal.timeout(cloudRequestTimeoutMs), |
| 654 | }); |
| 655 | } catch (error) { |
| 656 | throw new Error(`Studio request ${url} failed`, { cause: error }); |
| 657 | } |
| 658 | if (response.status === 204) { |
| 659 | return null; |
| 660 | } |
| 661 | if (!response.ok) { |
| 662 | throw new Error( |
| 663 | `${url} failed with ${response.status}: ${await response.text()}`, |
| 664 | ); |
| 665 | } |
| 666 | return response.json(); |
| 667 | } |
| 668 | |
| 669 | function sleep(ms) { |
| 670 | return new Promise((resolve) => setTimeout(resolve, ms)); |
no test coverage detected