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 });
|
const chat = await getChatById({ id });
|
||||||
|
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
let title = 'New Chat';
|
const title = await generateTitleFromUserMessage({
|
||||||
try {
|
|
||||||
const generatedTitle = await generateTitleFromUserMessage({
|
|
||||||
message,
|
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({
|
await saveChat({
|
||||||
id,
|
id,
|
||||||
|
|
@ -187,22 +173,6 @@ export async function POST(request: Request) {
|
||||||
|
|
||||||
let finalMergedUsage: AppUsage | undefined;
|
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({
|
const stream = createUIMessageStream({
|
||||||
execute: ({ writer: dataStream }) => {
|
execute: ({ writer: dataStream }) => {
|
||||||
const result = streamText({
|
const result = streamText({
|
||||||
|
|
@ -293,16 +263,7 @@ export async function POST(request: Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: () => {
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
return 'Oops, an error occurred!';
|
return 'Oops, an error occurred!';
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -323,13 +284,12 @@ export async function POST(request: Request) {
|
||||||
return error.toResponse();
|
return error.toResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for Vercel AI Gateway credit card error
|
||||||
if (
|
if (
|
||||||
error instanceof Error &&
|
error instanceof Error &&
|
||||||
(error.message?.includes(
|
error.message?.includes(
|
||||||
'AI Gateway requires a valid credit card on file to service requests',
|
'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();
|
return new ChatSDKError('bad_request:activate_gateway').toResponse();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,7 @@ export function Chat({
|
||||||
if (error instanceof ChatSDKError) {
|
if (error instanceof ChatSDKError) {
|
||||||
// Check if it's a credit card error
|
// Check if it's a credit card error
|
||||||
if (
|
if (
|
||||||
error.message?.includes('AI Gateway requires a valid credit card') ||
|
error.message?.includes('AI Gateway requires a valid credit card')
|
||||||
error.message?.includes('AI Gateway authentication failed') ||
|
|
||||||
error.message?.includes('No authentication provided')
|
|
||||||
) {
|
) {
|
||||||
setShowCreditCardAlert(true);
|
setShowCreditCardAlert(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue