( response: Response, fallbackMessage: string, )
| 66 | } |
| 67 | |
| 68 | async function readJsonOrThrow<T>( |
| 69 | response: Response, |
| 70 | fallbackMessage: string, |
| 71 | ): Promise<T> { |
| 72 | if (response.ok) { |
| 73 | return (await response.json()) as T |
| 74 | } |
| 75 | |
| 76 | const payload = (await response.json().catch(() => null)) as { |
| 77 | error?: string |
| 78 | } | null |
| 79 | |
| 80 | throw new Error( |
| 81 | payload && typeof payload === 'object' && 'error' in payload |
| 82 | ? String(payload.error ?? fallbackMessage) |
| 83 | : fallbackMessage, |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | async function requestJson<T>( |
| 88 | url: URL, |
no outgoing calls
no test coverage detected