gracefully handle SSE parse errors and suppress raw parser code (#367)
Closes #187 Closes #358 --------- Co-authored-by: Thibault Sottiaux <tibo@openai.com>
This commit is contained in:
@@ -791,6 +791,41 @@ export class AgentLoop {
|
|||||||
this.onLoading(false);
|
this.onLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Suppress internal stack on JSON parse failures
|
||||||
|
if (err instanceof SyntaxError) {
|
||||||
|
this.onItem({
|
||||||
|
id: `error-${Date.now()}`,
|
||||||
|
type: "message",
|
||||||
|
role: "system",
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "input_text",
|
||||||
|
text: "⚠️ Failed to parse streaming response (invalid JSON). Please `/clear` to reset.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
this.onLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Handle OpenAI API quota errors
|
||||||
|
if (
|
||||||
|
err instanceof Error &&
|
||||||
|
(err as { code?: string }).code === "insufficient_quota"
|
||||||
|
) {
|
||||||
|
this.onItem({
|
||||||
|
id: `error-${Date.now()}`,
|
||||||
|
type: "message",
|
||||||
|
role: "system",
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "input_text",
|
||||||
|
text: "⚠️ Insufficient quota. Please check your billing details and retry.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
this.onLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
this.currentStream = null;
|
this.currentStream = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user