(path: string, params?: Record<string, string>)
| 16 | } |
| 17 | |
| 18 | export function buildAPIUrl(path: string, params?: Record<string, string>): URL { |
| 19 | const baseUrl = path.startsWith('/api/') ? getInternalApiBaseUrl() : getBaseUrl() |
| 20 | const url = new URL(path, baseUrl) |
| 21 | |
| 22 | if (params) { |
| 23 | for (const [key, value] of Object.entries(params)) { |
| 24 | if (value !== undefined && value !== null) { |
| 25 | url.searchParams.set(key, value) |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return url |
| 31 | } |
| 32 | |
| 33 | export async function extractAPIErrorMessage(response: Response): Promise<string> { |
| 34 | const defaultMessage = `API request failed with status ${response.status}` |
no test coverage detected