(path: string, body?: unknown)
| 176 | } |
| 177 | |
| 178 | export async function patch<T>(path: string, body?: unknown): Promise<T> { |
| 179 | const hasBody = body !== undefined |
| 180 | const resp = await fetch(`${_baseUrl}${path}`, { |
| 181 | method: 'PATCH', |
| 182 | headers: { |
| 183 | ...getAuthHeaders(), |
| 184 | ...(hasBody && { 'Content-Type': 'application/json' }), |
| 185 | }, |
| 186 | ...(hasBody && { body: JSON.stringify(body) }), |
| 187 | }) |
| 188 | handle401(resp) |
| 189 | if (!resp.ok) { |
| 190 | const text = await resp.text().catch(() => '') |
| 191 | throw new Error(`HTTP ${resp.status}: ${text}`) |
| 192 | } |
| 193 | return resp.json() as Promise<T> |
| 194 | } |
no test coverage detected