mirror of
https://gh-proxy.org/https://github.com/klinsmaya/gateway.git
synced 2026-11-10 10:07:26 +08:00
fix: propagate response for failed fallbacks
This commit is contained in:
@@ -26,14 +26,6 @@ export async function chatCompletionsHandler(c: Context): Promise<Response> {
|
||||
"config"
|
||||
);
|
||||
|
||||
if (!tryTargetsResponse) {
|
||||
return new Response(errors[errors.length - 1].errorObj, {
|
||||
status: errors[errors.length - 1].status,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
}
|
||||
return tryTargetsResponse;
|
||||
} catch (err: any) {
|
||||
console.log("chatCompletion error", err.message);
|
||||
|
||||
@@ -27,14 +27,6 @@ export async function completionsHandler(c: Context): Promise<Response> {
|
||||
"config"
|
||||
);
|
||||
|
||||
if (!tryTargetsResponse) {
|
||||
return new Response(errors[errors.length - 1].errorObj, {
|
||||
status: errors[errors.length - 1].status,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
}
|
||||
return tryTargetsResponse;
|
||||
} catch (err: any) {
|
||||
console.log("completion error", err.message);
|
||||
|
||||
@@ -28,14 +28,6 @@ export async function embeddingsHandler(c: Context): Promise<Response> {
|
||||
"config"
|
||||
);
|
||||
|
||||
if (!tryTargetsResponse) {
|
||||
return new Response(errors[errors.length - 1].errorObj, {
|
||||
status: errors[errors.length - 1].status,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
}
|
||||
return tryTargetsResponse;
|
||||
} catch (err: any) {
|
||||
console.log("completion error", err.message);
|
||||
|
||||
@@ -429,8 +429,9 @@ export async function tryPost(c: Context, providerOption:Options, inputParams: P
|
||||
// If the response was not ok, throw an error
|
||||
if (!response.ok) {
|
||||
// Check if this request needs to be retried
|
||||
const errorObj: any = new Error(await mappedResponse.text());
|
||||
const errorObj: any = new Error(await mappedResponse.clone().text());
|
||||
errorObj.status = mappedResponse.status;
|
||||
errorObj.response = mappedResponse
|
||||
throw errorObj;
|
||||
}
|
||||
|
||||
@@ -502,7 +503,7 @@ export async function tryTargetsRecursively(
|
||||
errors: any,
|
||||
jsonPath: string,
|
||||
inheritedConfig: Record<string, any> = {}
|
||||
): Promise<Response | undefined> {
|
||||
): Promise<Response> {
|
||||
let currentTarget: any = {...targetGroup};
|
||||
let currentJsonPath = jsonPath;
|
||||
const strategyMode = currentTarget.strategy?.mode;
|
||||
@@ -614,6 +615,7 @@ export async function tryTargetsRecursively(
|
||||
currentJsonPath
|
||||
);
|
||||
} catch (error: any) {
|
||||
response = error.response;
|
||||
errors.push({
|
||||
provider: targetGroup.provider,
|
||||
errorObj: error.message,
|
||||
|
||||
Reference in New Issue
Block a user