Revert "fix(auth): show gateway dialog for all authentication errors" (#1230)
This commit is contained in:
parent
b6c8ea011f
commit
466478ccc4
2 changed files with 8 additions and 50 deletions
|
|
@ -127,23 +127,9 @@ export async function POST(request: Request) {
|
|||
const chat = await getChatById({ id });
|
||||
|
||||
if (!chat) {
|
||||
let title = 'New Chat';
|
||||
try {
|
||||
const generatedTitle = await generateTitleFromUserMessage({
|
||||
const title = await generateTitleFromUserMessage({
|
||||
message,
|
||||
});
|
||||
title = generatedTitle;
|
||||
} catch (titleError) {
|
||||
if (
|
||||
titleError instanceof Error &&
|
||||
(titleError.message?.includes('AI Gateway authentication failed') ||
|
||||
titleError.message?.includes('No authentication provided') ||
|
||||
titleError.message?.includes('AI Gateway requires a valid credit card'))
|
||||
) {
|
||||
throw titleError;
|
||||
}
|
||||
console.warn('Title generation failed, using default:', titleError);
|
||||
}
|
||||
|
||||
await saveChat({
|
||||
id,
|
||||
|
|
@ -187,22 +173,6 @@ export async function POST(request: Request) {
|
|||
|
||||
let finalMergedUsage: AppUsage | undefined;
|
||||
|
||||
try {
|
||||
await myProvider.languageModel(selectedChatModel).doGenerate({
|
||||
prompt: [{ role: 'user', content: [{ type: 'text', text: 'test' }] }],
|
||||
maxOutputTokens: 1,
|
||||
});
|
||||
} catch (testError) {
|
||||
if (
|
||||
testError instanceof Error &&
|
||||
(testError.message?.includes('AI Gateway authentication failed') ||
|
||||
testError.message?.includes('No authentication provided') ||
|
||||
testError.message?.includes('AI Gateway requires a valid credit card'))
|
||||
) {
|
||||
throw testError;
|
||||
}
|
||||
}
|
||||
|
||||
const stream = createUIMessageStream({
|
||||
execute: ({ writer: dataStream }) => {
|
||||
const result = streamText({
|
||||
|
|
@ -293,16 +263,7 @@ export async function POST(request: Request) {
|
|||
}
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
// Check for Vercel AI Gateway authentication errors
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.message?.includes('AI Gateway authentication failed') ||
|
||||
error.message?.includes('No authentication provided') ||
|
||||
error.message?.includes('AI Gateway requires a valid credit card'))
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
onError: () => {
|
||||
return 'Oops, an error occurred!';
|
||||
},
|
||||
});
|
||||
|
|
@ -323,13 +284,12 @@ export async function POST(request: Request) {
|
|||
return error.toResponse();
|
||||
}
|
||||
|
||||
// Check for Vercel AI Gateway credit card error
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.message?.includes(
|
||||
error.message?.includes(
|
||||
'AI Gateway requires a valid credit card on file to service requests',
|
||||
) ||
|
||||
error.message?.includes('AI Gateway authentication failed') ||
|
||||
error.message?.includes('No authentication provided'))
|
||||
)
|
||||
) {
|
||||
return new ChatSDKError('bad_request:activate_gateway').toResponse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ export function Chat({
|
|||
if (error instanceof ChatSDKError) {
|
||||
// Check if it's a credit card error
|
||||
if (
|
||||
error.message?.includes('AI Gateway requires a valid credit card') ||
|
||||
error.message?.includes('AI Gateway authentication failed') ||
|
||||
error.message?.includes('No authentication provided')
|
||||
error.message?.includes('AI Gateway requires a valid credit card')
|
||||
) {
|
||||
setShowCreditCardAlert(true);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue