-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy patherrorBanner.tsx
More file actions
55 lines (50 loc) · 2.01 KB
/
errorBanner.tsx
File metadata and controls
55 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use client';
import { Button } from '@/components/ui/button';
import { serviceErrorSchema } from '@/lib/serviceError';
import { CONTEXT_WINDOW_USER_MESSAGE } from '@/features/chat/utils';
import { AlertCircle, X } from "lucide-react";
import { useMemo } from 'react';
interface ErrorBannerProps {
error: Error;
isVisible: boolean;
onClose: () => void;
}
export const ErrorBanner = ({ error, isVisible, onClose }: ErrorBannerProps) => {
const errorMessage = useMemo(() => {
try {
const errorJson = JSON.parse(error.message);
const serviceError = serviceErrorSchema.parse(errorJson);
return serviceError.message;
} catch {
return error.message;
}
}, [error]);
if (!isVisible) {
return null;
}
return (
<div className="bg-red-50 border-b border-red-200 dark:bg-red-950/20 dark:border-red-800">
<div className="max-w-5xl mx-auto px-4 py-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<AlertCircle className="h-4 w-4 text-red-600 dark:text-red-400" />
<span className="text-sm font-medium text-red-800 dark:text-red-200">
{errorMessage === CONTEXT_WINDOW_USER_MESSAGE ? 'Context limit exceeded' : 'Error occurred'}
</span>
<span className="text-sm text-red-600 dark:text-red-400">
{errorMessage}
</span>
</div>
<Button
variant="ghost"
size="sm"
onClick={onClose}
className="h-6 w-6 p-0 text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-200"
>
<X className="h-4 w-4" />
</Button>
</div>
</div>
</div>
);
}