fix(sdk-js): non-ok response is not throwing anymore

This commit is contained in:
Tat Dat Duong
2025-02-11 08:45:15 -08:00
parent 7a2eb614dc
commit bb3193c83e
2 changed files with 6 additions and 7 deletions
+3 -6
View File
@@ -165,8 +165,7 @@ class BaseClient {
signal?: AbortSignal;
},
): Promise<T> {
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,
+3 -1
View File
@@ -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<typeof fetch>): ReturnType<typeof fetch> {
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))),
);