Skip to content

Commit 8afa049

Browse files
committed
fix: catch gateway error gracefully
1 parent 5718005 commit 8afa049

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/handlers/handlerUtils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,12 @@ export async function tryTargetsRecursively(
790790
// tryPost always returns a Response.
791791
// TypeError will check for all unhandled exceptions.
792792
// GatewayError will check for all handled exceptions which cannot allow the request to proceed.
793-
if (error instanceof TypeError || error instanceof GatewayError) {
793+
if (
794+
error instanceof TypeError ||
795+
error instanceof GatewayError ||
796+
!error.response ||
797+
(error.response && !(error.response instanceof Response))
798+
) {
794799
console.error(
795800
'tryTargetsRecursively error: ',
796801
error.message,

src/handlers/services/providerContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import {
88
import Providers from '../../providers';
99
import { RequestContext } from './requestContext';
1010
import { ANTHROPIC, AZURE_OPEN_AI } from '../../globals';
11+
import { GatewayError } from '../../errors/GatewayError';
1112

1213
export class ProviderContext {
1314
constructor(private provider: string) {
1415
if (!Providers[provider]) {
15-
throw new Error(`Provider ${provider} not found`);
16+
throw new GatewayError(`Provider ${provider} not found`);
1617
}
1718
}
1819

0 commit comments

Comments
 (0)