Skip to content

Commit 49ba1d5

Browse files
authored
fix: gateway error not showing in ui (#1441)
1 parent 5c941dd commit 49ba1d5

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

app/(chat)/api/chat/route.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,17 @@ export async function POST(request: Request) {
220220
});
221221
}
222222
},
223-
onError: () => "Oops, an error occurred!",
223+
onError: (error) => {
224+
if (
225+
error instanceof Error &&
226+
error.message?.includes(
227+
"AI Gateway requires a valid credit card on file to service requests",
228+
)
229+
) {
230+
return "AI Gateway requires a valid credit card on file to service requests. Please visit https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dadd-credit-card to add a card and unlock your free credits.";
231+
}
232+
return "Oops, an error occurred!";
233+
},
224234
});
225235

226236
return createUIMessageStreamResponse({

components/chat.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ export function Chat({
138138
mutate(unstable_serialize(getChatHistoryPaginationKey));
139139
},
140140
onError: (error) => {
141-
if (error instanceof ChatbotError) {
142-
if (
143-
error.message?.includes("AI Gateway requires a valid credit card")
144-
) {
145-
setShowCreditCardAlert(true);
146-
} else {
147-
toast({
148-
type: "error",
149-
description: error.message,
150-
});
151-
}
141+
if (error.message?.includes("AI Gateway requires a valid credit card")) {
142+
setShowCreditCardAlert(true);
143+
} else if (error instanceof ChatbotError) {
144+
toast({
145+
type: "error",
146+
description: error.message,
147+
});
148+
} else {
149+
toast({
150+
type: "error",
151+
description: error.message || "Oops, an error occurred!",
152+
});
152153
}
153154
},
154155
});

0 commit comments

Comments
 (0)