Mintplex-Labs/anything-llm · error
Internal Server Error
Error message
Internal Server Error
What it means
HTTP 500 from the catch-all of GET /embed/:embedId/:sessionId (public embed chat-history retrieval). EmbedChats.forEmbedByUser wraps Prisma in try/catch and returns [] on failure, so the realistic escape is convertToChatHistory throwing on a malformed embed chat row. The embed config itself is already validated by the validEmbedConfig middleware, so a missing embed yields a different (404/403) response, not this 500.
Source
Thrown at server/endpoints/embed/index.js:87
app.get(
"/embed/:embedId/:sessionId",
[validEmbedConfig],
async (request, response) => {
try {
const { sessionId } = request.params;
const embed = response.locals.embedConfig;
const history = await EmbedChats.forEmbedByUser(
embed.id,
sessionId,
null,
null,
true
);
response.status(200).json({ history: convertToChatHistory(history) });
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
}
}
);
app.delete(
"/embed/:embedId/:sessionId",
[validEmbedConfig],
async (request, response) => {
try {
const { sessionId } = request.params;
const embed = response.locals.embedConfig;
await EmbedChats.markHistoryInvalid(embed.id, sessionId);
response.status(200).end();
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
}View on GitHub (pinned to 526360e320)
Solutions
- Check the server log for the convertToChatHistory stack trace to locate the bad row.
- Clear the affected session's history via DELETE /embed/:embedId/:sessionId (markHistoryInvalid) so the widget starts fresh.
- If recurring, audit the embed_chats table for rows with NULL or non-JSON chat columns and repair them.
- Verify DB connectivity if the error coincides with other DB-bound failures.
Defensive patterns
Strategy: fallback
Validate before calling
// Embed history is best-effort — confirm the embed/session before relying on history.
async function safeEmbedHistory(embedBaseUrl, embedId, sessionId) {
const res = await fetch(`${embedBaseUrl}/embed/${embedId}/${sessionId}`);
if (!res.ok) return { history: [] };
return res.json();
} Try / catch
// Embed widgets should treat a 500 as 'no recoverable history' and start fresh.
try {
const res = await fetch(`${embedBaseUrl}/embed/${embedId}/${sessionId}`);
if (res.ok) return await res.json();
} catch (e) { /* network */ }
return { history: [] }; // degrade silently for end users Prevention
- Treat embed history as non-critical: render an empty state on failure rather than blocking the widget.
- Clear a persistently-failing session via DELETE /embed/:embedId/:sessionId so users get a clean slate.
- Monitor for corrupt embed_chats rows after upgrades.
When it happens
Trigger: An embed widget requests history for a sessionId whose stored chat row has a corrupt or unparsable JSON payload; or the DB drops during the query in a way that escapes the model's catch.
Common situations: Long-lived embed sessions whose rows predate a schema change; partial writes from a browser that disconnected mid-stream; storage-level corruption on the embed_chats table.
Understand the failure class
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/a8a78b6483aa38a1.
Report an issue: GitHub.