Skip to content

Commit 22a244b

Browse files
committed
fix(chat): handle neuron limit error gracefully
1 parent 36c77ee commit 22a244b

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎apps/site/src/pages/api/chat.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,19 @@ export const POST: APIRoute = async ({ request }) => {
394394
await writer.write(encoder.encode(part.text));
395395
} else if (part.type === "error") {
396396
console.error("[Stream Part Error]", (part as any).error);
397-
await writer.write(
398-
encoder.encode(
399-
`\n\n[Model Stream Error: ${(part as any).error instanceof Error ? (part as any).error.message : JSON.stringify((part as any).error)}]`,
400-
),
401-
);
397+
const errMsg =
398+
(part as any).error instanceof Error
399+
? (part as any).error.message
400+
: JSON.stringify((part as any).error);
401+
if (errMsg.includes("4006") || errMsg.includes("neurons")) {
402+
await writer.write(
403+
encoder.encode(
404+
"Cloudflare Workers AI daily free neuron allocation (10,000 neurons) has been reached. To continue chatting, upgrade to Cloudflare Workers Paid ($5/mo) or provide an AI API key.",
405+
),
406+
);
407+
} else {
408+
await writer.write(encoder.encode(`\n\n[Error: ${errMsg}]`));
409+
}
402410
}
403411
}
404412
if (!hasOutput) {

0 commit comments

Comments
 (0)