Skip to content

Commit 51f68f5

Browse files
committed
sync
1 parent 6596783 commit 51f68f5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • packages/console/app/src/routes/zen/util

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export async function handler(
187187
// Try another provider => stop retrying if using fallback provider
188188
if (
189189
res.status !== 200 &&
190+
// ie. 400 error is usually provider error like malformed request
191+
res.status !== 400 &&
190192
// ie. openai 404 error: Item with id 'msg_0ead8b004a3b165d0069436a6b6834819896da85b63b196a3f' not found.
191193
res.status !== 404 &&
192194
// ie. cannot change codex model providers mid-session
@@ -226,7 +228,7 @@ export async function handler(
226228
logger.debug("STATUS: " + res.status + " " + res.statusText)
227229

228230
// Handle non-streaming response
229-
if (!isStream || res.status === 429) {
231+
if (!isStream || [400, 404, 429].includes(res.status)) {
230232
const json = await res.json()
231233
await rateLimiter?.track()
232234
if (json.usage) {
@@ -238,6 +240,9 @@ export async function handler(
238240
await reload(billingSource, authInfo, costInfo)
239241
json.cost = calculateOccurredCost(billingSource, costInfo)
240242
}
243+
if (res.status === 400) {
244+
logger.metric({ "error.response": JSON.stringify(json) })
245+
}
241246
if (json.error?.message) {
242247
json.error.message = `Error from provider${providerInfo.displayName ? ` (${providerInfo.displayName})` : ""}: ${json.error.message}`
243248
}
@@ -393,7 +398,7 @@ export async function handler(
393398
type: "error",
394399
error: {
395400
type: "error",
396-
message: error.message,
401+
message: "Internal server error",
397402
},
398403
}),
399404
{ status: 500 },

0 commit comments

Comments
 (0)