Skip to content

Commit 5ec1427

Browse files
authored
Revert "fix credit card gateway error (#1231)"
This reverts commit 2c36a54.
1 parent 2c36a54 commit 5ec1427

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

components/chat.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { VisibilityType } from './visibility-selector';
1414
import { useArtifactSelector } from '@/hooks/use-artifact';
1515
import { unstable_serialize } from 'swr/infinite';
1616
import { getChatHistoryPaginationKey } from './sidebar-history';
17+
import { toast } from './toast';
1718
import type { Session } from 'next-auth';
1819
import { useSearchParams } from 'next/navigation';
1920
import { useChatVisibility } from '@/hooks/use-chat-visibility';
@@ -62,8 +63,7 @@ export function Chat({
6263

6364
const [input, setInput] = useState<string>('');
6465
const [usage, setUsage] = useState<AppUsage | undefined>(initialLastContext);
65-
const [showErrorAlert, setShowErrorAlert] = useState(false);
66-
const [errorMessage, setErrorMessage] = useState('');
66+
const [showCreditCardAlert, setShowCreditCardAlert] = useState(false);
6767
const [currentModelId, setCurrentModelId] = useState(initialChatModel);
6868
const currentModelIdRef = useRef(currentModelId);
6969

@@ -108,8 +108,17 @@ export function Chat({
108108
},
109109
onError: (error) => {
110110
if (error instanceof ChatSDKError) {
111-
setErrorMessage(error.message);
112-
setShowErrorAlert(true);
111+
// Check if it's a credit card error
112+
if (
113+
error.message?.includes('AI Gateway requires a valid credit card')
114+
) {
115+
setShowCreditCardAlert(true);
116+
} else {
117+
toast({
118+
type: 'error',
119+
description: error.message,
120+
});
121+
}
113122
}
114123
},
115124
});
@@ -209,8 +218,8 @@ export function Chat({
209218
/>
210219

211220
<AlertDialog
212-
open={showErrorAlert}
213-
onOpenChange={setShowErrorAlert}
221+
open={showCreditCardAlert}
222+
onOpenChange={setShowCreditCardAlert}
214223
>
215224
<AlertDialogContent>
216225
<AlertDialogHeader>

0 commit comments

Comments
 (0)