|
| 1 | +import { Button, Flex, Text } from '@radix-ui/themes' |
| 2 | +import { ExternalLink, KeyIcon, RefreshCw } from 'lucide-react' |
| 3 | + |
| 4 | +import grotCrashed from '@/assets/grot-crashed.svg' |
| 5 | +import { useSettingsChanged } from '@/hooks/useSettings' |
| 6 | +import { useStudioUIStore } from '@/store/ui' |
| 7 | + |
| 8 | +interface AutoCorrelationErrorProps { |
| 9 | + error: Error |
| 10 | + onRetry: () => void |
| 11 | +} |
| 12 | + |
| 13 | +export function ErrorMessage({ error, onRetry }: AutoCorrelationErrorProps) { |
| 14 | + const errorMessage = error.message.toLowerCase() |
| 15 | + const openSettingsDialog = useStudioUIStore( |
| 16 | + (state) => state.openSettingsDialog |
| 17 | + ) |
| 18 | + |
| 19 | + useSettingsChanged(() => { |
| 20 | + onRetry() |
| 21 | + }) |
| 22 | + |
| 23 | + const retryButton = ( |
| 24 | + <Button onClick={onRetry}> |
| 25 | + <RefreshCw /> |
| 26 | + Retry |
| 27 | + </Button> |
| 28 | + ) |
| 29 | + |
| 30 | + const openSettingsButton = ( |
| 31 | + <Button onClick={() => openSettingsDialog('ai')}> |
| 32 | + <KeyIcon /> |
| 33 | + Settings |
| 34 | + </Button> |
| 35 | + ) |
| 36 | + |
| 37 | + const reportIssueButton = ( |
| 38 | + <Button onClick={() => window.studio.ui.reportIssue()} variant="outline"> |
| 39 | + <ExternalLink /> |
| 40 | + Report issue |
| 41 | + </Button> |
| 42 | + ) |
| 43 | + |
| 44 | + if (errorMessage.includes('incorrect api key')) { |
| 45 | + return ( |
| 46 | + <MessageContent |
| 47 | + title="Incorrect API key" |
| 48 | + message="The OpenAI API key is incorrect or has been revoked. Check your API key in settings." |
| 49 | + > |
| 50 | + {openSettingsButton} |
| 51 | + </MessageContent> |
| 52 | + ) |
| 53 | + } |
| 54 | + |
| 55 | + if (errorMessage.includes('context window')) { |
| 56 | + return ( |
| 57 | + <MessageContent |
| 58 | + title="Token usage limit exceeded" |
| 59 | + message="The recording exceeds the token limit. Try reducing the number of allowed hosts in your recording or work with a smaller recording." |
| 60 | + /> |
| 61 | + ) |
| 62 | + } |
| 63 | + |
| 64 | + if (errorMessage.includes('rate limit')) { |
| 65 | + return ( |
| 66 | + <MessageContent |
| 67 | + title="Too many requests" |
| 68 | + message="You have exceeded the API rate limit. Wait a moment and try again." |
| 69 | + > |
| 70 | + {retryButton} |
| 71 | + </MessageContent> |
| 72 | + ) |
| 73 | + } |
| 74 | + |
| 75 | + return ( |
| 76 | + <MessageContent |
| 77 | + title="Something went wrong" |
| 78 | + message="An unexpected error occurred during auto-correlation. Click retry to try again or report an issue if problem persists." |
| 79 | + > |
| 80 | + {retryButton} |
| 81 | + {reportIssueButton} |
| 82 | + </MessageContent> |
| 83 | + ) |
| 84 | +} |
| 85 | + |
| 86 | +function MessageContent({ |
| 87 | + title, |
| 88 | + message, |
| 89 | + children, |
| 90 | +}: { |
| 91 | + title: string |
| 92 | + message: React.ReactNode |
| 93 | + children?: React.ReactNode |
| 94 | +}) { |
| 95 | + return ( |
| 96 | + <Flex |
| 97 | + direction="column" |
| 98 | + align="center" |
| 99 | + gap="6" |
| 100 | + justify="center" |
| 101 | + height="100%" |
| 102 | + p="6" |
| 103 | + > |
| 104 | + <img |
| 105 | + css={{ |
| 106 | + maxWidth: '200px', |
| 107 | + transform: 'scaleX(-1)', |
| 108 | + }} |
| 109 | + src={grotCrashed} |
| 110 | + aria-label="Error illustration" |
| 111 | + /> |
| 112 | + |
| 113 | + <Flex direction="column" align="center" gap="3" maxWidth="400px"> |
| 114 | + <Text size="4" weight="medium" align="center"> |
| 115 | + {title} |
| 116 | + </Text> |
| 117 | + |
| 118 | + <Text size="2" color="gray" align="center"> |
| 119 | + {message} |
| 120 | + </Text> |
| 121 | + |
| 122 | + <Flex gap="3" mt="4"> |
| 123 | + {children} |
| 124 | + </Flex> |
| 125 | + </Flex> |
| 126 | + </Flex> |
| 127 | + ) |
| 128 | +} |
0 commit comments