(url: string, options?: RequestInit)
| 37 | const API_BASE = '/api' |
| 38 | |
| 39 | async function fetchJSON<T>(url: string, options?: RequestInit): Promise<T> { |
| 40 | const response = await fetch(`${API_BASE}${url}`, { |
| 41 | ...options, |
| 42 | headers: { |
| 43 | 'Content-Type': 'application/json', |
| 44 | ...options?.headers, |
| 45 | }, |
| 46 | }) |
| 47 | |
| 48 | if (!response.ok) { |
| 49 | const error = await response.json().catch(() => ({ detail: 'Unknown error' })) |
| 50 | throw new Error(error.detail || `HTTP ${response.status}`) |
| 51 | } |
| 52 | |
| 53 | // Handle 204 No Content responses |
| 54 | if (response.status === 204) { |
| 55 | return undefined as T |
| 56 | } |
| 57 | |
| 58 | return response.json() |
| 59 | } |
| 60 | |
| 61 | // ============================================================================ |
| 62 | // Projects API |
no outgoing calls
no test coverage detected