sync
This commit is contained in:
@@ -187,6 +187,8 @@ export async function handler(
|
|||||||
// Try another provider => stop retrying if using fallback provider
|
// Try another provider => stop retrying if using fallback provider
|
||||||
if (
|
if (
|
||||||
res.status !== 200 &&
|
res.status !== 200 &&
|
||||||
|
// ie. 400 error is usually provider error like malformed request
|
||||||
|
res.status !== 400 &&
|
||||||
// ie. openai 404 error: Item with id 'msg_0ead8b004a3b165d0069436a6b6834819896da85b63b196a3f' not found.
|
// ie. openai 404 error: Item with id 'msg_0ead8b004a3b165d0069436a6b6834819896da85b63b196a3f' not found.
|
||||||
res.status !== 404 &&
|
res.status !== 404 &&
|
||||||
// ie. cannot change codex model providers mid-session
|
// ie. cannot change codex model providers mid-session
|
||||||
@@ -226,7 +228,7 @@ export async function handler(
|
|||||||
logger.debug("STATUS: " + res.status + " " + res.statusText)
|
logger.debug("STATUS: " + res.status + " " + res.statusText)
|
||||||
|
|
||||||
// Handle non-streaming response
|
// Handle non-streaming response
|
||||||
if (!isStream || res.status === 429) {
|
if (!isStream || [400, 404, 429].includes(res.status)) {
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
await rateLimiter?.track()
|
await rateLimiter?.track()
|
||||||
if (json.usage) {
|
if (json.usage) {
|
||||||
@@ -238,6 +240,9 @@ export async function handler(
|
|||||||
await reload(billingSource, authInfo, costInfo)
|
await reload(billingSource, authInfo, costInfo)
|
||||||
json.cost = calculateOccurredCost(billingSource, costInfo)
|
json.cost = calculateOccurredCost(billingSource, costInfo)
|
||||||
}
|
}
|
||||||
|
if (res.status === 400) {
|
||||||
|
logger.metric({ "error.response": JSON.stringify(json) })
|
||||||
|
}
|
||||||
if (json.error?.message) {
|
if (json.error?.message) {
|
||||||
json.error.message = `Error from provider${providerInfo.displayName ? ` (${providerInfo.displayName})` : ""}: ${json.error.message}`
|
json.error.message = `Error from provider${providerInfo.displayName ? ` (${providerInfo.displayName})` : ""}: ${json.error.message}`
|
||||||
}
|
}
|
||||||
@@ -393,7 +398,7 @@ export async function handler(
|
|||||||
type: "error",
|
type: "error",
|
||||||
error: {
|
error: {
|
||||||
type: "error",
|
type: "error",
|
||||||
message: error.message,
|
message: "Internal server error",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{ status: 500 },
|
{ status: 500 },
|
||||||
|
|||||||
Reference in New Issue
Block a user