From bb3193c83e8e3b70e0975c51f5f3ad1f4ef303ac Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 10 Feb 2025 17:54:58 -0800 Subject: [PATCH] fix(sdk-js): non-ok response is not throwing anymore --- libs/sdk-js/src/client.ts | 9 +++------ libs/sdk-js/src/utils/async_caller.ts | 4 +++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 54ce7733b..c4ffcb7ed 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -165,8 +165,7 @@ class BaseClient { signal?: AbortSignal; }, ): Promise { - const response = await this.asyncCaller.call( - _getFetchImplementation(), + const response = await this.asyncCaller.fetch( ...this.prepareFetchOptions(path, options), ); if (response.status === 202 || response.status === 204) { @@ -784,8 +783,7 @@ export class RunsClient< const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`; - const response = await this.asyncCaller.call( - _getFetchImplementation(), + const response = await this.asyncCaller.fetch( ...this.prepareFetchOptions(endpoint, { method: "POST", json, @@ -1077,8 +1075,7 @@ export class RunsClient< ? { signal: options } : options; - const response = await this.asyncCaller.call( - _getFetchImplementation(), + const response = await this.asyncCaller.fetch( ...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, { method: "GET", timeoutMs: null, diff --git a/libs/sdk-js/src/utils/async_caller.ts b/libs/sdk-js/src/utils/async_caller.ts index d5de9131a..72beefb54 100644 --- a/libs/sdk-js/src/utils/async_caller.ts +++ b/libs/sdk-js/src/utils/async_caller.ts @@ -1,5 +1,6 @@ import pRetry from "p-retry"; import PQueueMod from "p-queue"; +import { _getFetchImplementation } from "../singletons/fetch.js"; const STATUS_NO_RETRY = [ 400, // Bad Request @@ -210,7 +211,8 @@ export class AsyncCaller { } fetch(...args: Parameters): ReturnType { - const fetchFn = this.customFetch ?? fetch; + const fetchFn = + this.customFetch ?? (_getFetchImplementation() as typeof fetch); return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))), );