diff --git a/lib/data/gantt-api.ts b/lib/data/gantt-api.ts index df37ebc..683c389 100644 --- a/lib/data/gantt-api.ts +++ b/lib/data/gantt-api.ts @@ -21,7 +21,13 @@ function deriveApiBaseUrlFromGanttBoardUrl(): string | null { try { const parsed = new URL(ganttBoardUrl); const pathname = parsed.pathname.replace(/\/+$/, ""); - parsed.pathname = `${pathname}/api`; + if (!pathname || pathname === "/") { + parsed.pathname = "/api"; + } else if (pathname.endsWith("/api")) { + parsed.pathname = pathname; + } else { + parsed.pathname = `${pathname}/api`; + } parsed.search = ""; parsed.hash = ""; return normalizeBaseUrl(parsed.toString()); @@ -107,11 +113,11 @@ export async function fetchGanttApi(endpoint: string): Promise { payload?.error || payload?.message || (nonJsonBody ? nonJsonBody.replace(/\s+/g, " ").slice(0, 200) : response.statusText); - throw new Error(`gantt-board API request failed (${response.status} ${endpoint}): ${details}`); + throw new Error(`gantt-board API request failed (${response.status} ${cacheKey}): ${details}`); } if (!isJson) { - throw new Error(`gantt-board API request failed (${response.status} ${endpoint}): expected JSON response`); + throw new Error(`gantt-board API request failed (${response.status} ${cacheKey}): expected JSON response`); } return payload as T;