@@ -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
847829export function constructConfigFromRequestHeaders (
0 commit comments