danny-avila/LibreChat · warning · Error
Unexpected response from server; Status: ${response.status}
Error message
Unexpected response from server; Status: ${response.status} ${response.statusText} What it means
Thrown by the abort handler when the `POST {endpoint}/abort` request returns a response that is neither JSON nor a clean 200/204. The handler treats JSON responses via `finalHandler`/`cancelHandler` (and a JSON 404 as a silent stop), and 200/204 non-JSON as success; anything else (e.g. 401, 403, 500, or a non-JSON 404) falls through to this throw. The thrown error is caught immediately and surfaced in the chat as an error message — it is not re-thrown.
Source
Thrown at client/src/hooks/SSE/useEventHandlers.ts:1092
});
// Check if the response is JSON
const contentType = response.headers.get('content-type');
if (contentType != null && contentType.includes('application/json')) {
const data = await response.json();
if (response.status === 404) {
setIsSubmitting(false);
return;
}
if (data.final === true) {
finalHandler(data, submission);
} else {
cancelHandler(data, submission);
}
} else if (response.status === 204 || response.status === 200) {
setIsSubmitting(false);
} else {
throw new Error(
'Unexpected response from server; Status: ' +
response.status +
' ' +
response.statusText,
);
}
} catch (error) {
const errorResponse = createErrorMessage({
getMessages,
submission,
error,
});
setMessages([...submission.messages, submission.userMessage, errorResponse]);
if (newConversation) {
newConversation({
template: { conversationId: conversationId || errorResponse.conversationId || v4() },
preset: tPresetSchema.parse(submission.conversation),
});View on GitHub (pinned to 5ff282f900)
Solutions
- Inspect the captured `response.status`/`statusText` — 401 means re-authenticate, 5xx/502/504 means the upstream is unhealthy, 404 non-JSON means the route is missing.
- For 401, trigger a token refresh / re-login flow before retrying the abort.
- For proxy HTML error pages, ensure the abort route is registered and returns JSON, and configure the proxy to pass through application responses.
- Because the error is already caught and shown in-chat, no further handling is strictly required; the user can retry or re-authenticate.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check auth before aborting
if (!token) throw new Error('Not authenticated');
// Or: refresh token if it may be near expiry
if (tokenExpired(token)) await refreshToken(); Type guard
function isJsonResponse(response: Response): boolean {
return (response.headers.get('content-type') ?? '').includes('application/json');
} Try / catch
try {
const response = await fetch(`${EndpointURLs[endpoint]}/abort`, { ... });
if (!response.ok && !isJsonResponse(response) && ![200, 204].includes(response.status)) {
throw new Error(`Unexpected response: ${response.status}`);
}
} catch (err) {
createErrorMessage({ getMessages, submission, error: err }); // already surfaced in-chat
} Prevention
- Refresh the JWT before it expires in long-running chats to avoid 401 abort failures.
- Ensure the /abort route is registered and returns JSON, and that proxies pass application responses through.
- Treat 5xx/proxy HTML errors as transient and let the user retry.
When it happens
Trigger: The abort endpoint returns 401 because the user's JWT expired mid-conversation; 403 due to authorization changes; 500 from a server-side error during abort processing; the server returns an HTML error page (non-JSON) with a 404/500 status (e.g. a reverse-proxy 502/504 page); the endpoint route is misconfigured and returns a non-JSON body.
Common situations: Long-running chat where the JWT expires before the user hits stop; a reverse proxy (nginx) returning an HTML 502/504 when the upstream abort handler is down; the abort route returning the wrong content-type; deployment where the `/abort` route is missing and returns a non-JSON 404.
Related errors
- [retrieveRun] Failed to retrieve run data:
- Failed to send email via Mailgun
- Download failed: ${response.status} ${response.statusText}
- Request failed with status ${response.status}: ${json.error.
- Invalid response from the STT API
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/d264a2b969c2ed79.
Report an issue: GitHub.