Skip to content

Commit 654600c

Browse files
authored
Merge pull request #1241 from Portkey-AI/fix/llm-error-response-log-addition
fix: handle provider error logs addition
2 parents ae7a615 + 6614335 commit 654600c

2 files changed

Lines changed: 24 additions & 49 deletions

File tree

src/handlers/handlerUtils.ts

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -795,53 +795,35 @@ export async function tryTargetsRecursively(
795795
// tryPost always returns a Response.
796796
// TypeError will check for all unhandled exceptions.
797797
// GatewayError will check for all handled exceptions which cannot allow the request to proceed.
798-
if (
799-
error instanceof TypeError ||
800-
error instanceof GatewayError ||
801-
!error.response ||
802-
(error.response && !(error.response instanceof Response))
803-
) {
804-
console.error(
805-
'tryTargetsRecursively error: ',
806-
error.message,
807-
error.cause,
808-
error.stack
809-
);
810-
const errorMessage =
811-
error instanceof GatewayError
812-
? error.message
813-
: 'Something went wrong';
814-
response = new Response(
815-
JSON.stringify({
816-
status: 'failure',
817-
message: errorMessage,
818-
}),
819-
{
820-
status: 500,
821-
headers: {
822-
'content-type': 'application/json',
823-
// Add this header so that the fallback loop can be interrupted if its an exception.
824-
'x-portkey-gateway-exception': 'true',
825-
},
826-
}
827-
);
828-
} else {
829-
response = error.response;
830-
if (isHandlingCircuitBreaker) {
831-
await c.get('recordCircuitBreakerFailure')?.(
832-
env(c),
833-
currentInheritedConfig.id,
834-
currentTarget.cbConfig,
835-
currentJsonPath,
836-
response.status
837-
);
798+
console.error(
799+
'tryTargetsRecursively error: ',
800+
error.message,
801+
error.cause,
802+
error.stack
803+
);
804+
const errorMessage =
805+
error instanceof GatewayError
806+
? error.message
807+
: 'Something went wrong';
808+
response = new Response(
809+
JSON.stringify({
810+
status: 'failure',
811+
message: errorMessage,
812+
}),
813+
{
814+
status: 500,
815+
headers: {
816+
'content-type': 'application/json',
817+
// Add this header so that the fallback loop can be interrupted if its an exception.
818+
'x-portkey-gateway-exception': 'true',
819+
},
838820
}
839-
}
821+
);
840822
}
841823
break;
842824
}
843825

844-
return response;
826+
return response!;
845827
}
846828

847829
export function constructConfigFromRequestHeaders(

src/handlers/services/responseService.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ export class ResponseService {
6262

6363
this.updateHeaders(finalMappedResponse, cache.cacheStatus, retryAttempt);
6464

65-
if (!finalMappedResponse.ok) {
66-
const errorObj: any = new Error(await finalMappedResponse.clone().text());
67-
errorObj.status = finalMappedResponse.status;
68-
errorObj.response = finalMappedResponse;
69-
throw errorObj;
70-
}
71-
7265
return {
7366
response: finalMappedResponse,
7467
responseJson,

0 commit comments

Comments
 (0)