fix: propagate response for failed fallbacks

This commit is contained in:
visargD
2024-01-27 12:05:22 +05:30
parent 4b9abe76ab
commit 0a0cf7d877
4 changed files with 4 additions and 26 deletions
-8
View File
@@ -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);
-8
View File
@@ -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);
-8
View File
@@ -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);
+4 -2
View File
@@ -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,