fix: enhance error logging with additional context in analysis and moderation processes

This commit is contained in:
MythEclipse
2026-05-18 23:48:02 +07:00
parent 6339d741a9
commit 069cf105f3
3 changed files with 40 additions and 6 deletions
+9 -4
View File
@@ -529,11 +529,16 @@ Return ONLY valid JSON, no other text.`;
try {
parsed = parseModerationResponse(content, targetIds);
} catch (parseError) {
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
log.error(
{
error:
parseError instanceof Error ? parseError.message : String(parseError),
content,
error: errorMsg,
contentLength: content.length,
contentPreview: content.substring(0, 500),
fullContent: content,
targetIds,
model: config.AI_LLM_MODEL,
timestamp: new Date().toISOString(),
},
"Robust Fallback: Failed to parse moderation response. Defaulting all targets to clean.",
);
@@ -542,7 +547,7 @@ Return ONLY valid JSON, no other text.`;
status: "clean",
flags: [],
score: 0.1,
analysis: `Parsing failed: ${parseError instanceof Error ? parseError.message : String(parseError)}. Defaulted to clean.`,
analysis: `Parsing failed: ${errorMsg}. Defaulted to clean.`,
}));
}