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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -103,12 +103,14 @@ export default function TextNode({ id, data, selected }: NodeProps<TextNode>) {
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
onDoubleClick={() => setIsEditing(true)}
|
||||
className="min-h-[2rem] cursor-text whitespace-pre-wrap break-words text-sm"
|
||||
onClick={() => {
|
||||
if (selected) setIsEditing(true);
|
||||
}}
|
||||
className="nodrag nowheel min-h-[2rem] cursor-text whitespace-pre-wrap break-words text-sm"
|
||||
>
|
||||
{content || (
|
||||
<span className="text-muted-foreground">
|
||||
Doppelklick zum Bearbeiten
|
||||
Auswählen, dann hier klicken
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user