unslothai/unsloth · error

Request failed (${res.status})

Error message

Request failed (${res.status})

What it means

Fallback error from parseJsonOrThrow in prompts-api.ts: the response was non-ok AND the body either failed to parse as JSON or had no detail field. When detail exists the server's text is used instead; this generic 'Request failed (status)' is the last resort. It covers all prompt entry/list endpoints (/api/prompts/entries, /entries/bulk).

Source

Thrown at studio/frontend/src/features/chat/api/prompts-api.ts:26

  name: string;
  text: string;
  createdAt: number;
  updatedAt: number;
}

export interface PromptListEntry {
  id: string;
  name: string;
  items: string[];
  createdAt: number;
  updatedAt: number;
}

async function parseJsonOrThrow<T>(res: Response): Promise<T> {
  const body = await res.json().catch(() => null);
  if (!res.ok) {
    const detail = (body as { detail?: string } | null)?.detail;
    throw new Error(detail ?? `Request failed (${res.status})`);
  }
  return body as T;
}

export async function listPromptEntries(): Promise<PromptEntry[]> {
  const res = await authFetch("/api/prompts/entries");
  const data = await parseJsonOrThrow<{ entries: PromptEntry[] }>(res);
  return data.entries;
}

export async function savePromptEntry(entry: PromptEntry): Promise<PromptEntry> {
  const res = await authFetch(`/api/prompts/entries/${entry.id}`, {
    method: "PUT",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(entry),
  });
  return parseJsonOrThrow<PromptEntry>(res);
}

View on GitHub (pinned to 203007d190)

Solutions

  1. Treat the bare status text as 'no structured error available' and check server/proxy logs for the real cause.
  2. 502/503: restart or verify the studio backend.
  3. 401/403: re-authenticate.
  4. If you control the server, always include a JSON {detail} in error responses so clients get actionable text.
Defensive patterns

Strategy: try-catch

Try / catch

try { return await parseJsonOrThrow<T>(res); }
catch (e) {
  if (/Request failed \((5\d\d|50[23])\)/.test(String(e))) { await waitForBackend(); return retry(); }
  throw e;
}

Prevention

When it happens

Trigger: GET/PUT/POST to /api/prompts/... returning an error with an empty or non-JSON body — e.g. a 500 with a bare HTML error page, a 502 from a dead backend, or 401 with no body.

Common situations: Prompts backend down (502/503 from gateway); reverse proxy returning HTML error pages that fail JSON parsing; auth middleware rejecting before the route body exists.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/583c9f2bcfeb984f. Report an issue: GitHub.