error response consistency, human readible1
This commit is contained in:
@@ -87,15 +87,27 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
const data = await res.json();
|
||||
const raw = data.response?.trim() ?? '';
|
||||
|
||||
const parsed = JSON.parse(raw);
|
||||
const jsonMatch = raw.match(/\{[\s\S]*\}/);
|
||||
if (!jsonMatch) {
|
||||
logger.warn('[entities] No JSON object found in response');
|
||||
logger.debug('[entities] Raw response was:', raw);
|
||||
return;
|
||||
}
|
||||
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(jsonMatch[0]);
|
||||
} catch (err) {
|
||||
logger.warn('[entities] Failed to parse extraction response:', err.message);
|
||||
logger.debug('[entities] Raw response was:', raw);
|
||||
return;
|
||||
}
|
||||
const entities = Array.isArray(parsed.entities) ? parsed.entities : [];
|
||||
if (entities.length === 0) {
|
||||
logger.debug('[entities] No entities found in this exchange — skipping');
|
||||
return; // not an error, just nothing to extract
|
||||
}
|
||||
|
||||
if (!Array.isArray(entities)) throw new Error('Response was not a JSON array');
|
||||
|
||||
let saved = 0;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user