{"record":{"id":"19c59fdfe97271af","repo":"SillyTavern/SillyTavern","slug":"internal-server-error","errorCode":null,"errorMessage":"Internal server error","messagePattern":"Internal server error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"critical","filePath":"src/endpoints/anthropic.js","lineNumber":64,"sourceCode":"        if (!result.ok) {\n            const text = await result.text();\n            console.warn(`Claude API returned error: ${result.status} ${result.statusText}`, text);\n            return response.status(result.status).send({ error: true });\n        }\n\n        /** @type {any} */\n        const generateResponseJson = await result.json();\n        const caption = generateResponseJson.content[0].text;\n        console.debug('Claude response:', generateResponseJson);\n\n        if (!caption) {\n            return response.status(500).send('No caption found');\n        }\n\n        return response.json({ caption });\n    } catch (error) {\n        console.error(error);\n        response.status(500).send('Internal server error');\n    }\n});\n","sourceCodeStart":46,"sourceCodeEnd":67,"githubUrl":"https://github.com/SillyTavern/SillyTavern/blob/8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8/src/endpoints/anthropic.js#L46-L67","documentation":"Generic HTTP 500 returned by the Anthropic captioning route's top-level `catch (error)`. Any unhandled exception inside the handler — a thrown fetch error, a JSON parse failure on the upstream body, or a missing `content[0]` — lands here and is logged via `console.error` while the client receives a generic message.","triggerScenarios":"Any unexpected throw in the route: upstream network failure, `result.json()` body not valid JSON, `generateResponseJson.content` being undefined so `[0].text` throws, or a missing API key causing the initial fetch to reject.","commonSituations":"Anthropic API key unset/invalid; network egress blocked; response schema change where `content` is absent; transient upstream 5xx that wasn't `result.ok`-gated cleanly.","solutions":["Check the server console for the specific `console.error` output to identify the real exception.","Confirm the Anthropic API key is configured and valid.","Verify network connectivity to the Anthropic API from the server.","If the upstream shape changed, harden access to `content[0].text` with optional chaining."],"exampleFix":"// before\nconst caption = generateResponseJson.content[0].text;\n\n// after\nconst caption = generateResponseJson?.content?.[0]?.text;","handlingStrategy":"try-catch","validationCode":"// preflight before the request\nif (!process.env.ANTHROPIC_API_KEY) {\n    return response.status(503).send('Anthropic API key not configured.');\n}","typeGuard":"null","tryCatchPattern":"try {\n    // ... captioning logic with hardened access\n} catch (error) {\n    console.error('Caption route failed:', error);\n    const status = error?.status || 500;\n    response.status(status).send(error?.message?.includes('API key') ? 'Caption service unavailable' : 'Internal server error');\n}","preventionTips":["Always read nested upstream fields with optional chaining (`json?.content?.[0]?.text`).","Garden-wall the route: validate config (API key), input image, and network before calling upstream.","Log the real error server-side while returning a generic message to the client.","Pre-flight the API key and return 503 instead of a 500 stack-trace path."],"tags":["anthropic","caption","api","unhandled","http-500"],"backgroundTag":null,"analyzedSha":"8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8","analyzedAt":"2026-08-13T07:48:40.832Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}