fix: complete generated runtime route wiring

This commit is contained in:
2026-09-23 10:03:59 +09:00
parent 89024d3b01
commit 6f9dc7ab41
2 changed files with 19 additions and 9 deletions
@@ -138,15 +138,18 @@ async function fetchJson(
if (!response.ok) {
let detail = `${response.status} ${response.statusText}`.trim();
try {
const body = await response.json();
if (typeof body?.message === "string") detail = body.message;
else if (typeof body?.error === "string") detail = body.error;
const body: unknown = await response.json();
if (typeof body === "object" && body !== null && !Array.isArray(body)) {
const record = body as Record<string, unknown>;
if (typeof record.message === "string") detail = record.message.slice(0, 512);
else if (typeof record.error === "string") detail = record.error.slice(0, 512);
}
} catch {
// Preserve the bounded status text when the Backend did not return JSON.
}
throw new WorkspaceCatalogError(response.status, detail);
}
return await response.json() as unknown;
return await response.json();
}
function errorMessage(error: unknown): string {
@@ -24,11 +24,18 @@ function workerPath(workspaceId: string, worker: WorkerActionTarget): string {
async function responseError(response: Response): Promise<string> {
const fallback = `${response.status} ${response.statusText}`.trim();
try {
const payload = await response.json() as {
message?: string;
error?: { message?: string };
};
return payload.error?.message ?? payload.message ?? fallback;
const payload: unknown = await response.json();
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
return fallback;
}
const record = payload as Record<string, unknown>;
if (typeof record.message === "string") return record.message.slice(0, 512);
const nested = record.error;
if (typeof nested === "object" && nested !== null && !Array.isArray(nested)) {
const message = (nested as Record<string, unknown>).message;
if (typeof message === "string") return message.slice(0, 512);
}
return fallback;
} catch {
return fallback;
}