( url: string, options?: RequestInit, )
| 2 | import { agentNativePath } from "@agent-native/core/client"; |
| 3 | |
| 4 | export async function apiFetch( |
| 5 | url: string, |
| 6 | options?: RequestInit, |
| 7 | ): Promise<any> { |
| 8 | const res = await fetch(agentNativePath(url), { |
| 9 | ...options, |
| 10 | headers: { |
| 11 | "Content-Type": "application/json", |
| 12 | "X-Request-Source": TAB_ID, |
| 13 | ...options?.headers, |
| 14 | }, |
| 15 | }); |
| 16 | if (res.status === 204) return null; |
| 17 | const data = await res.json(); |
| 18 | if (!res.ok) { |
| 19 | const err = new Error(data?.error || `HTTP ${res.status}`) as Error & { |
| 20 | details?: any; |
| 21 | }; |
| 22 | err.details = data?.details; |
| 23 | throw err; |
| 24 | } |
| 25 | return data; |
| 26 | } |
no test coverage detected