Skip to content

Commit c40a24a

Browse files
authored
exception fix (#883)
1 parent 6c4a5bc commit c40a24a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

backend/nodejs/apps/src/modules/knowledge_base/controllers/kb_controllers.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,9 @@ export const getRecordBuffer =
23442344
);
23452345

23462346
// Set appropriate headers from the FastAPI response
2347-
res.set('Content-Type', response.headers['content-type']);
2347+
if (response.headers['content-type']) {
2348+
res.set('Content-Type', response.headers['content-type']);
2349+
}
23482350
if (response.headers['content-disposition']) {
23492351
res.set('Content-Disposition', response.headers['content-disposition']);
23502352
}
@@ -2357,7 +2359,11 @@ export const getRecordBuffer =
23572359
console.error('Stream error:', error);
23582360
// Only send error if headers haven't been sent yet
23592361
if (!res.headersSent) {
2360-
throw new InternalServerError('Error streaming data');
2362+
try {
2363+
res.status(500).end('Error streaming data');
2364+
} catch (e) {
2365+
logger.error('Failed to send stream error response to client', { error: e });
2366+
}
23612367
}
23622368
});
23632369
} catch (error: any) {
@@ -2369,7 +2375,9 @@ export const getRecordBuffer =
23692375
error: error.response.data || 'Error from AI backend',
23702376
});
23712377
} else {
2372-
throw new InternalServerError('Failed to retrieve record data');
2378+
// Don't throw here to avoid uncaughtException shutdown during streams
2379+
res.status(500).json({ error: 'Failed to retrieve record data' });
2380+
return;
23732381
}
23742382
}
23752383
const handleError = handleBackendError(error, 'get record buffer');

0 commit comments

Comments
 (0)