(path: string, body?: unknown, signal?: AbortSignal)
| 88 | } |
| 89 | |
| 90 | export async function post<T>(path: string, body?: unknown, signal?: AbortSignal): Promise<T> { |
| 91 | const hasBody = body !== undefined |
| 92 | const resp = await fetch(`${_baseUrl}${path}`, { |
| 93 | method: 'POST', |
| 94 | headers: { |
| 95 | ...getAuthHeaders(), |
| 96 | ...(hasBody && { 'Content-Type': 'application/json' }), |
| 97 | }, |
| 98 | ...(hasBody && { body: JSON.stringify(body) }), |
| 99 | signal, |
| 100 | }) |
| 101 | handle401(resp) |
| 102 | if (!resp.ok) { |
| 103 | const text = await resp.text().catch(() => '') |
| 104 | throw new Error(`HTTP ${resp.status}: ${text}`) |
| 105 | } |
| 106 | return resp.json() as Promise<T> |
| 107 | } |
| 108 | |
| 109 | // ==================== 分析请求取消(epoch)==================== |
| 110 | // |
no test coverage detected