feat: implement error classification and handling for AI generation limits

- Added error classification for daily generation cap and concurrency limits in the PromptNode component, improving user feedback during AI image generation failures.
- Enhanced toast notifications to provide specific messages for daily limit and concurrent job errors.
- Introduced internal mutations in the credits module to check abuse limits and track usage, ensuring better resource management and user experience.
- Updated AI error handling logic to categorize and respond to different error types effectively.
This commit is contained in:
Matthias
2026-03-28 11:31:11 +01:00
parent 4b4d784768
commit e5f27d7d29
6 changed files with 193 additions and 12 deletions

View File

@@ -38,6 +38,7 @@ import { Sparkles, Loader2, Coins } from "lucide-react";
import { useRouter } from "next/navigation";
import { toast } from "@/lib/toast";
import { msg } from "@/lib/toast-messages";
import { classifyError } from "@/lib/ai-errors";
type PromptNodeData = {
prompt?: string;
@@ -257,7 +258,21 @@ export default function PromptNode({
},
);
} catch (err) {
setError(err instanceof Error ? err.message : msg.ai.generationFailed.title);
const classified = classifyError(err);
if (classified.category === "daily_cap") {
toast.error(
msg.billing.dailyLimitReached(0).title,
"Morgen stehen wieder Generierungen zur Verfügung.",
);
} else if (classified.category === "concurrency") {
toast.warning(
msg.ai.concurrentLimitReached.title,
msg.ai.concurrentLimitReached.desc,
);
} else {
setError(classified.message || msg.ai.generationFailed.title);
}
} finally {
setIsGenerating(false);
}