Skip to content

Commit 2c36a54

Browse files
authored
fix credit card gateway error (#1231)
1 parent 466478c commit 2c36a54

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

components/chat.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ 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';
1817
import type { Session } from 'next-auth';
1918
import { useSearchParams } from 'next/navigation';
2019
import { useChatVisibility } from '@/hooks/use-chat-visibility';
@@ -63,7 +62,8 @@ export function Chat({
6362

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

@@ -108,17 +108,8 @@ export function Chat({
108108
},
109109
onError: (error) => {
110110
if (error instanceof ChatSDKError) {
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-
}
111+
setErrorMessage(error.message);
112+
setShowErrorAlert(true);
122113
}
123114
},
124115
});
@@ -218,8 +209,8 @@ export function Chat({
218209
/>
219210

220211
<AlertDialog
221-
open={showCreditCardAlert}
222-
onOpenChange={setShowCreditCardAlert}
212+
open={showErrorAlert}
213+
onOpenChange={setShowErrorAlert}
223214
>
224215
<AlertDialogContent>
225216
<AlertDialogHeader>

0 commit comments

Comments
 (0)