fix: complete generated runtime route wiring
This commit is contained in:
@@ -138,15 +138,18 @@ async function fetchJson(
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
let detail = `${response.status} ${response.statusText}`.trim();
|
let detail = `${response.status} ${response.statusText}`.trim();
|
||||||
try {
|
try {
|
||||||
const body = await response.json();
|
const body: unknown = await response.json();
|
||||||
if (typeof body?.message === "string") detail = body.message;
|
if (typeof body === "object" && body !== null && !Array.isArray(body)) {
|
||||||
else if (typeof body?.error === "string") detail = body.error;
|
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 {
|
} catch {
|
||||||
// Preserve the bounded status text when the Backend did not return JSON.
|
// Preserve the bounded status text when the Backend did not return JSON.
|
||||||
}
|
}
|
||||||
throw new WorkspaceCatalogError(response.status, detail);
|
throw new WorkspaceCatalogError(response.status, detail);
|
||||||
}
|
}
|
||||||
return await response.json() as unknown;
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorMessage(error: unknown): string {
|
function errorMessage(error: unknown): string {
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ function workerPath(workspaceId: string, worker: WorkerActionTarget): string {
|
|||||||
async function responseError(response: Response): Promise<string> {
|
async function responseError(response: Response): Promise<string> {
|
||||||
const fallback = `${response.status} ${response.statusText}`.trim();
|
const fallback = `${response.status} ${response.statusText}`.trim();
|
||||||
try {
|
try {
|
||||||
const payload = await response.json() as {
|
const payload: unknown = await response.json();
|
||||||
message?: string;
|
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
||||||
error?: { message?: string };
|
return fallback;
|
||||||
};
|
}
|
||||||
return payload.error?.message ?? payload.message ?? 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 {
|
} catch {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user