Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh-dixit committed Feb 27, 2025
1 parent 7751b51 commit 9a6ec0d
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions js/src/sdk/models/backendClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import apiClient from "../client/client";
import { CEG } from "../utils/error";
import { COMPOSIO_SDK_ERROR_CODES } from "../utils/errors/src/constants";
import { removeTrailingSlashIfExists } from "../utils/string";
import { setAxiosClientConfig } from "../utils/config";

/**
* Class representing the details required to initialize and configure the API client.
Expand Down Expand Up @@ -35,16 +36,14 @@ export class AxiosBackendClient {
this.runtime = runtime || "";
this.apiKey = apiKey;
this.baseUrl = removeTrailingSlashIfExists(baseUrl);
this.instance = createClient(
createConfig({
baseURL: this.baseUrl,
headers: {
"X-API-KEY": `${this.apiKey}`,
"X-SOURCE": "js_sdk",
"X-RUNTIME": this.runtime,
},
})
);
this.instance = createClient(createConfig({
baseURL: this.baseUrl,
headers: {
"X-API-KEY": `${this.apiKey}`,
"X-SOURCE": "js_sdk",
"X-RUNTIME": this.runtime,
},
}));
if (!apiKey) {
throw CEG.getCustomError(
COMPOSIO_SDK_ERROR_CODES.COMMON.API_KEY_UNAVAILABLE,
Expand All @@ -67,6 +66,8 @@ export class AxiosBackendClient {
}
);
}

this.initializeApiClient();
}

/**
Expand All @@ -84,7 +85,24 @@ export class AxiosBackendClient {
throw CEG.handleAllError(error);
}
}
/**
* Initializes the API client with the provided configuration.
* @private
*/
private initializeApiClient() {
this.instance.setConfig({
baseURL: removeTrailingSlashIfExists(this.baseUrl),
headers: {
"X-API-KEY": `${this.apiKey}`,
"X-SOURCE": "js_sdk",
"X-RUNTIME": this.runtime,
},
throwOnError: true,
});

setAxiosClientConfig(this.instance.instance);
}

getAxiosInstance() {
return this.instance.instance;
}
Expand Down

0 comments on commit 9a6ec0d

Please sign in to comment.