fix credit card gateway error (#1231)

This commit is contained in:
josh 2025-09-21 13:18:18 +01:00 committed by GitHub
parent 466478ccc4
commit 2c36a54c94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,6 @@ import type { VisibilityType } from './visibility-selector';
import { useArtifactSelector } from '@/hooks/use-artifact'; import { useArtifactSelector } from '@/hooks/use-artifact';
import { unstable_serialize } from 'swr/infinite'; import { unstable_serialize } from 'swr/infinite';
import { getChatHistoryPaginationKey } from './sidebar-history'; import { getChatHistoryPaginationKey } from './sidebar-history';
import { toast } from './toast';
import type { Session } from 'next-auth'; import type { Session } from 'next-auth';
import { useSearchParams } from 'next/navigation'; import { useSearchParams } from 'next/navigation';
import { useChatVisibility } from '@/hooks/use-chat-visibility'; import { useChatVisibility } from '@/hooks/use-chat-visibility';
@ -63,7 +62,8 @@ export function Chat({
const [input, setInput] = useState<string>(''); const [input, setInput] = useState<string>('');
const [usage, setUsage] = useState<AppUsage | undefined>(initialLastContext); const [usage, setUsage] = useState<AppUsage | undefined>(initialLastContext);
const [showCreditCardAlert, setShowCreditCardAlert] = useState(false); const [showErrorAlert, setShowErrorAlert] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [currentModelId, setCurrentModelId] = useState(initialChatModel); const [currentModelId, setCurrentModelId] = useState(initialChatModel);
const currentModelIdRef = useRef(currentModelId); const currentModelIdRef = useRef(currentModelId);
@ -108,17 +108,8 @@ export function Chat({
}, },
onError: (error) => { onError: (error) => {
if (error instanceof ChatSDKError) { if (error instanceof ChatSDKError) {
// Check if it's a credit card error setErrorMessage(error.message);
if ( setShowErrorAlert(true);
error.message?.includes('AI Gateway requires a valid credit card')
) {
setShowCreditCardAlert(true);
} else {
toast({
type: 'error',
description: error.message,
});
}
} }
}, },
}); });
@ -218,8 +209,8 @@ export function Chat({
/> />
<AlertDialog <AlertDialog
open={showCreditCardAlert} open={showErrorAlert}
onOpenChange={setShowCreditCardAlert} onOpenChange={setShowErrorAlert}
> >
<AlertDialogContent> <AlertDialogContent>
<AlertDialogHeader> <AlertDialogHeader>