{"record":{"id":"4f8d551131ee7826","repo":"SillyTavern/SillyTavern","slug":"internal-server-error-4f8d55","errorCode":null,"errorMessage":"Internal server error","messagePattern":"Internal server error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/endpoints/minimax.js","lineNumber":225,"sourceCode":"                const mimeType = getAudioMimeType(format);\n\n                response.setHeader('Content-Type', mimeType);\n                response.setHeader('Content-Length', audioBuffer.byteLength);\n\n                return response.send(Buffer.from(audioBuffer));\n            } catch (urlError) {\n                console.error('MiniMax TTS: Error fetching audio from URL:', urlError);\n                return response.status(500).json({ error: `Failed to fetch audio: ${urlError.message}` });\n            }\n        } else {\n            // Handle error response\n            const errorMessage = responseData.base_resp?.status_msg || responseData.error?.message || 'Unknown error';\n            console.error('MiniMax TTS: No valid audio data in response:', responseData);\n            return response.status(500).json({ error: `API Error: ${errorMessage}` });\n        }\n    } catch (error) {\n        console.error('MiniMax TTS generation failed:', error);\n        return response.status(500).json({ error: 'Internal server error' });\n    }\n});\n","sourceCodeStart":207,"sourceCodeEnd":228,"githubUrl":"https://github.com/SillyTavern/SillyTavern/blob/06bde939fb1e9c4c8d8641d810f0a916b5bce127/src/endpoints/minimax.js#L207-L228","documentation":"This is the top-level catch-all of the MiniMax TTS POST route in src/endpoints/minimax.js:226. Any exception thrown anywhere in the surrounding try block — during request construction, the MiniMax API fetch, response parsing, or audio extraction — falls through to this handler and is returned to the client as a generic HTTP 500 'Internal server error'. The real cause is logged to console.error but hidden from the response, so the client cannot distinguish a network failure from an auth failure or a malformed response.","triggerScenarios":"The MiniMax API call throws (DNS/TCP failure, timeout, invalid JSON response), the response shape does not match expectations and a property access throws, or an error occurs in a code path not covered by the inner urlError catch (e.g. building the request body throws on undefined fields). Authentication errors (invalid group_id/api_key) that surface as thrown exceptions rather than handled status codes also land here.","commonSituations":"Expired or invalid MiniMax API key or group_id; network/firewall blocking api.minimaxi.com; MiniMax API schema change shifting the response shape; large text payloads hitting upstream timeouts; the audio-from-URL fetch failing in a way that escapes the inner catch.","solutions":["Inspect the server console output — the full error object is logged by console.error('MiniMax TTS generation failed:', error).","Verify the MiniMax API key and group_id are correctly set in the connection/secrets settings.","Confirm network connectivity to the MiniMax API host from the server.","Validate the request payload (model, voice, text) is complete and well-formed before the call.","Add more granular inner try/catch blocks that return a specific error message instead of relying on the generic 500."],"exampleFix":"// before\n    } catch (error) {\n        console.error('MiniMax TTS generation failed:', error);\n        return response.status(500).json({ error: 'Internal server error' });\n    }\n\n// after\n    } catch (error) {\n        console.error('MiniMax TTS generation failed:', error);\n        return response.status(500).json({\n            error: 'Internal server error',\n            detail: error?.message ?? String(error),\n        });\n    }","handlingStrategy":"try-catch","validationCode":"// Before calling MiniMax, validate required generation fields\nfunction validateMiniMaxRequest(body) {\n    const missing = ['model', 'text', 'voice'].filter(k => !body?.[k]);\n    if (missing.length) {\n        return { ok: false, error: `Missing fields: ${missing.join(', ')}` };\n    }\n    return { ok: true };\n}","typeGuard":"function isMiniMaxError(error) {\n    return error?.name === 'FetchError'\n        || error?.message?.includes('invalid json')\n        || error?.code === 'ECONNREFUSED';\n}","tryCatchPattern":"// Distinguish failure classes instead of one generic 500\ntry {\n    // ... MiniMax call ...\n} catch (error) {\n    if (error?.name === 'AbortError') {\n        return response.status(504).json({ error: 'MiniMax request timed out' });\n    }\n    if (error?.code === 'ECONNREFUSED' || error?.code === 'ENOTFOUND') {\n        return response.status(502).json({ error: 'Cannot reach MiniMax API' });\n    }\n    console.error('MiniMax TTS generation failed:', error);\n    return response.status(500).json({ error: 'Internal server error', detail: error?.message });\n}","preventionTips":["Always validate request body fields before constructing the upstream call.","Log the full error object server-side and return a sanitized detail to the client.","Set explicit fetch timeouts via AbortController to avoid hanging requests.","Add integration smoke-tests against a mock MiniMax to catch response-shape regressions."],"tags":["minimax","tts","error-handling","network","api"],"backgroundTag":null,"analyzedSha":"06bde939fb1e9c4c8d8641d810f0a916b5bce127","analyzedAt":"2026-08-13T07:48:40.832Z","contentChangedAt":"2026-08-13T07:48:40.832Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}