Skip to content

Commit 1affd8f

Browse files
committed
fix: refactor getClient method to return fetch client directly and update ApiOptions type
1 parent 62c6e50 commit 1affd8f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ class Api {
142142

143143
/**
144144
* Get the HTTP client to use for requests
145-
* @returns {Promise<FetchClient>} HTTP client
145+
* @returns {FetchClient} HTTP client
146146
* @throws {Error} If no client is available
147147
*/
148-
async getClient () {
148+
getClient () {
149149
if (this.options.mock) {
150150
console.warn('@beyonk/http: Using mocked http client')
151151
return this.options.mock
@@ -154,7 +154,7 @@ class Api {
154154
if (this.client) {
155155
return this.client
156156
} else if (config && config.fetch) {
157-
return await config.fetch()
157+
return config.fetch
158158
} else if (typeof window !== 'undefined') {
159159
return window.fetch.bind(window)
160160
}
@@ -210,7 +210,7 @@ class Api {
210210
this.config.overrides
211211
)
212212

213-
const client = await this.getClient()
213+
const client = this.getClient()
214214
const ep = this.config.query ? `${endpoint}?${this.config.query}` : `${endpoint}`
215215

216216
/** @type {QueryResult|undefined} */

lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export type ApiOptions = {
88
baseUrl?: string;
99
/** Mock client for testing */
1010
mock?: FetchClient;
11-
/** Function that returns a fetch client */
12-
fetch?: () => FetchClient | Promise<FetchClient>;
11+
/** Fetch client for HTTP requests */
12+
fetch?: FetchClient;
1313
/** Whether to retry failed requests */
1414
retry?: RetryOptions | false;
1515
/** Whether to parse error responses as JSON */

0 commit comments

Comments
 (0)