import type React from 'react' import { IErrorStateProps } from '../interfaces/IErrorStateProps' import { getString } from '../utils/getString' const { Button } = wp.components /** * Detect error type using explicit string matching */ export function detectErrorType(error: string): 'token_missing' | 'token_invalid' | 'general' { // Remove any leading numbers and clean the error message const cleanError = error.replace(/^\d+/, '').trim() const lowerError = cleanError.toLowerCase() // Token missing errors if ( lowerError.includes('not configured') || lowerError.includes('token not configured') || lowerError.includes('missing') || lowerError.includes('required') || lowerError.includes('configure your github personal access token') || lowerError.includes('personal access token') || (lowerError.includes('configure') && lowerError.includes('token')) ) { return 'token_missing' } // Token invalid errors if ( lowerError.includes('invalid') && lowerError.includes('token') ) { return 'token_invalid' } return 'general' } /** * Error state component with retry functionality */ export const ErrorState: React.FC = ({ error, onRetry, className = '', children }) => { // Use configurable error detection from global config const errorType = detectErrorType(error) // Get settings URL from global config const settingsUrl = window.githubReleaseBrowserConfig?.settingsUrl return (
{children || ( <> {errorType === 'token_missing' ? ( <>

{getString('error.welcome.title')}

{getString('error.welcome.description')}

{settingsUrl && ( )}
) : errorType === 'token_invalid' ? ( <>

{getString('error.title.invalidToken')}

{getString('error.desc.invalidToken')}

{settingsUrl && ( )}
) : ( <>
{error}
)} )}
) }