'use client' import React, { useState } from 'react' import { Button } from '@payloadcms/ui' interface ErrorDisplayProps { value?: string onChange?: (value: string) => void readOnly?: boolean path?: string } export const ErrorDisplay: React.FC = ({ value, onChange, readOnly = false }) => { const [expanded, setExpanded] = useState(false) if (!value) { return null } // Parse common error patterns const parseError = (error: string) => { // Check for different error types and provide user-friendly messages if (error.includes('Request timeout')) { return { type: 'timeout', title: 'Request Timeout', message: 'The HTTP request took too long to complete. Consider increasing the timeout value or checking the target server.', technical: error } } if (error.includes('Network error') || error.includes('fetch')) { return { type: 'network', title: 'Network Error', message: 'Unable to connect to the target server. Please check the URL and network connectivity.', technical: error } } if (error.includes('Hook execution failed')) { return { type: 'hook', title: 'Workflow Hook Failed', message: 'The workflow trigger hook encountered an error. This may be due to PayloadCMS initialization issues.', technical: error } } if (error.includes('Executor not available')) { return { type: 'executor', title: 'Workflow Engine Unavailable', message: 'The workflow execution engine is not properly initialized. Try restarting the server.', technical: error } } if (error.includes('Collection slug is required') || error.includes('Document data is required')) { return { type: 'validation', title: 'Invalid Input Data', message: 'Required fields are missing from the workflow step configuration. Please check your step inputs.', technical: error } } if (error.includes('status') && error.includes('4')) { return { type: 'client', title: 'Client Error (4xx)', message: 'The request was rejected by the server. Check your API credentials and request format.', technical: error } } if (error.includes('status') && error.includes('5')) { return { type: 'server', title: 'Server Error (5xx)', message: 'The target server encountered an error. This is usually temporary - try again later.', technical: error } } // Generic error return { type: 'generic', title: 'Workflow Error', message: 'An error occurred during workflow execution. See technical details below.', technical: error } } const errorInfo = parseError(value) const getErrorIcon = (type: string) => { switch (type) { case 'timeout': return '⏰' case 'network': return '🌐' case 'hook': return '🔗' case 'executor': return '⚙️' case 'validation': return '📋' case 'client': return '🚫' case 'server': return '🔥' default: return '❗' } } const getErrorColor = (type: string) => { switch (type) { case 'timeout': return '#F59E0B' case 'network': return '#EF4444' case 'hook': return '#8B5CF6' case 'executor': return '#6B7280' case 'validation': return '#F59E0B' case 'client': return '#EF4444' case 'server': return '#DC2626' default: return '#EF4444' } } const errorColor = getErrorColor(errorInfo.type) return (
{/* Error Header */}
{getErrorIcon(errorInfo.type)}

{errorInfo.title}

{errorInfo.message}

{/* Technical Details Toggle */}
{expanded && (
{errorInfo.technical}
)}
{/* Quick Actions */}
💡 Quick fixes:
    {errorInfo.type === 'timeout' && ( <>
  • Increase the timeout value in step configuration
  • Check if the target server is responding slowly
  • )} {errorInfo.type === 'network' && ( <>
  • Verify the URL is correct and accessible
  • Check firewall and network connectivity
  • )} {errorInfo.type === 'hook' && ( <>
  • Restart the PayloadCMS server
  • Check server logs for initialization errors
  • )} {errorInfo.type === 'executor' && ( <>
  • Restart the PayloadCMS application
  • Verify the automation plugin is properly configured
  • )} {errorInfo.type === 'validation' && ( <>
  • Check all required fields are filled in the workflow step
  • Verify JSONPath expressions in step inputs
  • )} {(errorInfo.type === 'client' || errorInfo.type === 'server') && ( <>
  • Check API credentials and permissions
  • Verify the request format matches API expectations
  • Try the request manually to test the endpoint
  • )} {errorInfo.type === 'generic' && ( <>
  • Check the workflow configuration
  • Review server logs for more details
  • Try running the workflow again
  • )}
{/* Hidden textarea for editing if needed */} {!readOnly && onChange && (