From 9de4b167e71b3caaf004481fbb91ab3b3ff666cd Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 23 Sep 2025 15:07:02 +0700 Subject: [PATCH] catch the error bubbled up exactly --- src/pages/Index.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index b35d3a02..6840eaae 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -13,6 +13,7 @@ import { OnboardingDialog } from '@/components/OnboardingDialog'; import { DotAI } from '@/lib/DotAI'; import { parseProviderModel } from '@/lib/parseProviderModel'; import type { AIMessage } from '@/lib/SessionManager'; +import { AuthenticationError } from 'openai'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; @@ -47,16 +48,9 @@ export default function Index() { // Check for API key failures and show appropriate toast const checkForKeyFailure = (error: unknown): boolean => { - if (!(error instanceof Error)) return false; - - const message = error.message.toLowerCase(); - const isAuthError = ( - message.includes('401') || - message.includes('unauthorized') || - message.includes('no auth credentials') || - message.includes('invalid api key') || - message.includes('authentication failed') - ); + // Check for authentication errors + // Note: useAIProjectId re-throws OpenAI errors as generic Error objects + const isAuthError = error instanceof Error && error.message === '401 No auth credentials found'; if (isAuthError) { // Get provider name inline