feat: enhance canvas and node components with error handling and retry logic
- Integrated retry logic for AI image generation to handle transient errors and improve user experience. - Updated error categorization to provide more informative feedback based on different failure scenarios. - Enhanced node components to display retry attempts and error messages, improving visibility during image generation failures. - Refactored canvas and node components to include retry count in status updates, ensuring accurate tracking of generation attempts.
This commit is contained in:
66
components/canvas/nodes/node-error-boundary.tsx
Normal file
66
components/canvas/nodes/node-error-boundary.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import type { ErrorInfo, ReactNode } from "react";
|
||||
import { Component } from "react";
|
||||
|
||||
interface NodeErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
nodeType: string;
|
||||
}
|
||||
|
||||
interface NodeErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export class NodeErrorBoundary extends Component<
|
||||
NodeErrorBoundaryProps,
|
||||
NodeErrorBoundaryState
|
||||
> {
|
||||
state: NodeErrorBoundaryState = {
|
||||
hasError: false,
|
||||
};
|
||||
|
||||
static getDerivedStateFromError(error: Error): NodeErrorBoundaryState {
|
||||
return {
|
||||
hasError: true,
|
||||
errorMessage: error.message,
|
||||
};
|
||||
}
|
||||
|
||||
override componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error("Node rendering error", {
|
||||
nodeType: this.props.nodeType,
|
||||
error,
|
||||
componentStack: errorInfo.componentStack,
|
||||
});
|
||||
}
|
||||
|
||||
private handleRetry = () => {
|
||||
this.setState({ hasError: false, errorMessage: undefined });
|
||||
};
|
||||
|
||||
override render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div className="m-2 rounded-md border border-destructive/40 bg-destructive/5 p-2 text-xs">
|
||||
<p className="font-medium text-destructive">Node render failed ({this.props.nodeType})</p>
|
||||
{this.state.errorMessage && (
|
||||
<p className="mt-1 truncate text-destructive/90" title={this.state.errorMessage}>
|
||||
{this.state.errorMessage}
|
||||
</p>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={this.handleRetry}
|
||||
className="nodrag mt-2 rounded border border-destructive/30 px-2 py-1 text-[11px] font-medium text-destructive transition-colors hover:bg-destructive/10"
|
||||
>
|
||||
Retry
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user