decolua/9router · error · Error
Request failed (${response.status})
Error message
Request failed (${response.status}) What it means
The dashboard basic-chat client calls its own /api chat endpoint and, when response.ok is false, parses the JSON body for `error` or `message`; if neither exists it falls back to a generic "Request failed (<status>)". So this exact message means the server returned an error HTTP status but a body without a readable error field (or the body wasn't JSON).
Source
Thrown at src/app/(dashboard)/dashboard/basic-chat/BasicChatPageClient.js:655
try {
const response = await fetch("/api/dashboard/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "text/event-stream",
},
body: JSON.stringify({
model: model.requestModel || model.id,
messages: requestMessages,
stream: true,
}),
signal: abortRef.current.signal,
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(textValue(errorData.error || errorData.message || `Request failed (${response.status})`));
}
const reader = response.body?.getReader();
if (!reader) {
const data = await response.json().catch(() => ({}));
const fallbackText = textValue(data?.choices?.[0]?.message?.content || data?.output_text || data?.error || data?.message || "");
updateSession(sessionId, (currentSession) => ({
...currentSession,
messages: currentSession.messages.map((message) => (message.id === assistantMessageId ? { ...message, content: fallbackText, status: "done" } : message)),
updatedAt: new Date().toISOString(),
}));
return;
}
const decoder = new TextDecoder();
let buffer = "";
let assistantText = "";
View on GitHub (pinned to 90b52e06ff)
Solutions
- Check the browser Network tab for the actual status code and raw response body to find the real cause.
- 401 → re-login to the dashboard (JWT session expired).
- 5xx → check the server logs at the corresponding /api/v1 handler for the upstream failure.
- Verify the gateway/upstream provider credentials and that the server is running at the expected PORT.
Example fix
// before
const errorData = await response.json().catch(() => ({}));
throw new Error(textValue(errorData.error || ...));
// after — also surface status + raw text for debugging
const raw = await response.text();
let errorData = {}; try { errorData = JSON.parse(raw); } catch {}
throw new Error(errorData.error || raw.slice(0, 200) || `Request failed (${response.status})`); Defensive patterns
Strategy: try-catch
Validate before calling
// client-side pre-flight: ensure a session exists and the API is up
const health = await fetch("/api/health", { signal }).catch(() => null);
if (!health?.ok) throw new Error("Gateway unavailable before chat request");
Type guard
const hasApiErrorBody = (d) => d && (typeof d.error === "string" || typeof d.message === "string");
Try / catch
if (!response.ok) {
const raw = await response.text();
let body = {}; try { body = JSON.parse(raw); } catch {}
const msg = body.error || body.message || (response.status === 401 ? "Session expired — please log in again" : `Request failed (${response.status}): ${raw.slice(0, 200)}`);
showError(msg);
return;
} Prevention
- Handle 401 by redirecting to login before showing a generic error.
- Show the HTTP status to users and log the raw body for support.
- Add abort/timeout handling so hung requests surface a clear message.
- Keep dashboard session cookies fresh; warn before JWT expiry.
When it happens
Trigger: POSTing a chat completion from BasicChatPageClient and receiving 4xx/5xx whose body lacks `error`/`message` — gateway 502 HTML page, 401 with empty body, or proxy-generated error pages.
Common situations: Server not running or crashed mid-deploy (502/504 from reverse proxy); session expired (401) with non-JSON body; upstream provider key missing so the API returned a bare status; rate-limit 429 with empty body.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Failed to fetch image: ${res.status}
- Upstream error (${res.status})
- Edge TTS voices fetch failed: ${res.status}
- OpenAI TTS failed: ${res.status}
- OpenRouter TTS failed: ${res.status}
AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30).
Data as JSON: /api/errors/78580596c0ec18ce.
Report an issue: GitHub.