debug: add stderr to error response
This commit is contained in:
16
server.js
16
server.js
@@ -49,13 +49,23 @@ app.post('/api/chat', (req, res) => {
|
|||||||
res.write(`data: ${JSON.stringify({ text: chunk.toString() })}\n\n`);
|
res.write(`data: ${JSON.stringify({ text: chunk.toString() })}\n\n`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let stderrBuf = '';
|
||||||
proc.stderr.on('data', (chunk) => {
|
proc.stderr.on('data', (chunk) => {
|
||||||
console.error('[claude stderr]', chunk.toString().substring(0, 300));
|
const s = chunk.toString();
|
||||||
|
stderrBuf += s;
|
||||||
|
console.error('[claude stderr]', s.substring(0, 500));
|
||||||
});
|
});
|
||||||
|
|
||||||
proc.on('close', (code) => {
|
proc.on('error', (err) => {
|
||||||
|
console.error('[spawn error]', err.message);
|
||||||
|
res.write(`data: ${JSON.stringify({ error: `spawn: ${err.message}` })}\n\n`);
|
||||||
|
});
|
||||||
|
|
||||||
|
proc.on('close', (code, signal) => {
|
||||||
|
console.log(`[claude close] code=${code} signal=${signal} stderr=${stderrBuf.substring(0,300)}`);
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
res.write(`data: ${JSON.stringify({ error: `Ошибка (code ${code}). Проверь auth: claude --version` })}\n\n`);
|
const msg = stderrBuf.trim() || `code=${code} signal=${signal}`;
|
||||||
|
res.write(`data: ${JSON.stringify({ error: msg.substring(0, 500) })}\n\n`);
|
||||||
}
|
}
|
||||||
res.write('data: [DONE]\n\n');
|
res.write('data: [DONE]\n\n');
|
||||||
res.end();
|
res.end();
|
||||||
|
|||||||
Reference in New Issue
Block a user