|
1 | 1 | import { AI21Error } from './errors';
|
2 | 2 | import { VERSION } from './version';
|
3 | 3 |
|
4 |
| -import { RequestOptions, FinalRequestOptions, APIResponseProps, HTTPMethod, Headers } from './types/index.js'; |
| 4 | +import { RequestOptions, FinalRequestOptions, APIResponseProps, HTTPMethod, Headers, UnifiedResponse } from './types'; |
5 | 5 | import { AI21EnvConfig } from './EnvConfig';
|
6 | 6 | import { handleAPIResponse } from './ResponseHandler';
|
7 | 7 | import { createFetchInstance } from 'envFetch';
|
@@ -90,25 +90,19 @@ export abstract class APIClient {
|
90 | 90 | }
|
91 | 91 |
|
92 | 92 | private async performRequest(options: FinalRequestOptions): Promise<APIResponseProps> {
|
93 |
| - const controller = new AbortController(); |
94 | 93 | const url = `${this.baseURL}${options.path}`;
|
95 | 94 |
|
96 | 95 | const headers = {
|
97 | 96 | ...this.defaultHeaders(options),
|
98 | 97 | ...options.headers,
|
99 | 98 | };
|
100 |
| - const response = await this.fetch.call(url, { |
101 |
| - method: options.method, |
102 |
| - headers: headers as any, |
103 |
| - signal: controller.signal, |
104 |
| - body: options.body ? JSON.stringify(options.body) : undefined, |
105 |
| - }); |
| 99 | + const response = await this.fetch.call(url, { ...options, headers }); |
106 | 100 |
|
107 | 101 | if (!response.ok) {
|
108 | 102 | throw new AI21Error(`Request failed with status ${response.status}. ${await response.text()}`);
|
109 | 103 | }
|
110 | 104 |
|
111 |
| - return { response, options, controller }; |
| 105 | + return { response: response as UnifiedResponse, options }; |
112 | 106 | }
|
113 | 107 |
|
114 | 108 | protected isRunningInBrowser(): boolean {
|
|
0 commit comments