()
| 14 | } |
| 15 | |
| 16 | export async function fetchSources(): Promise<DataSource[]> { |
| 17 | try { |
| 18 | const response = await fetch(`${API_BASE}/sources`); |
| 19 | |
| 20 | if (!response.ok) { |
| 21 | const errorMessage = await parseJsonResponse<{ error: string }>(response) |
| 22 | .then((data) => data.error) |
| 23 | .catch(() => response.statusText); |
| 24 | throw new ApiError(`Failed to fetch sources: ${errorMessage}`, response.status, response.statusText); |
| 25 | } |
| 26 | |
| 27 | return response.json(); |
| 28 | } catch (err) { |
| 29 | // Ensure all errors are ApiError instances |
| 30 | if (err instanceof ApiError) { |
| 31 | throw err; |
| 32 | } |
| 33 | // Network errors, timeout, etc. |
| 34 | throw new ApiError(err instanceof Error ? err.message : 'Network error', 0); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export async function fetchSource(sourceId: string): Promise<DataSource> { |
| 39 | try { |
no outgoing calls
no test coverage detected