(path: string, body?: unknown)
| 158 | } |
| 159 | |
| 160 | export async function put<T>(path: string, body?: unknown): Promise<T> { |
| 161 | const hasBody = body !== undefined |
| 162 | const resp = await fetch(`${_baseUrl}${path}`, { |
| 163 | method: 'PUT', |
| 164 | headers: { |
| 165 | ...getAuthHeaders(), |
| 166 | ...(hasBody && { 'Content-Type': 'application/json' }), |
| 167 | }, |
| 168 | ...(hasBody && { body: JSON.stringify(body) }), |
| 169 | }) |
| 170 | handle401(resp) |
| 171 | if (!resp.ok) { |
| 172 | const text = await resp.text().catch(() => '') |
| 173 | throw new Error(`HTTP ${resp.status}: ${text}`) |
| 174 | } |
| 175 | return resp.json() as Promise<T> |
| 176 | } |
| 177 | |
| 178 | export async function patch<T>(path: string, body?: unknown): Promise<T> { |
| 179 | const hasBody = body !== undefined |
no test coverage detected