Skip to content

Commit

Permalink
updated axios
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalk007 committed Oct 16, 2024
1 parent 9864fe0 commit a8a2892
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dist/**/*"
],
"dependencies": {
"axios": "^1.7.7",
"axios": "^0.28.0",
"axios-retry": "~3.2.5",
"https-proxy-agent": "^5.0.1"
},
Expand Down
35 changes: 33 additions & 2 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import axios, { AxiosError, AxiosInstance, AxiosProxyConfig, AxiosRequestConfig } from 'axios';
import axios, {
AxiosError,
AxiosInstance,
AxiosProxyConfig,
AxiosRequestConfig,
AxiosResponse,
AxiosResponseHeaders
} from 'axios';
import { IClientResponse, ILogger, IProxyConfig, RetryOnStatusCode } from '../model';
import axiosRetry, { IAxiosRetryConfig } from 'axios-retry';
import { HttpsProxyAgent } from 'https-proxy-agent';
Expand Down Expand Up @@ -56,9 +63,32 @@ export class HttpClient {
}

public async doRequest(requestParams: IRequestParams): Promise<IClientResponse> {
return await this._axiosInstance(requestParams);
const response : AxiosResponse = await this._axiosInstance(requestParams);
return {
data: response.data,
headers: this.mapHeaders(response.headers),
status: response.status
};
}

private mapHeaders(headers?: AxiosResponseHeaders): { [key: string]: string } {
const mappedHeaders: { [key: string]: string } = {};
if (!headers) {
return mappedHeaders; // Return an empty object if headers are undefined
}

Object.keys(headers).forEach((key) => {
const headerValue : string | undefined = headers[key];
if (headerValue !== undefined) {
mappedHeaders[key] = headerValue.toString();
}
});

return mappedHeaders;
}



public async doAuthRequest(requestParams: IRequestParams): Promise<IClientResponse> {
if (this._accessToken !== '') {
this.addAuthHeader(requestParams);
Expand All @@ -85,6 +115,7 @@ export class HttpClient {
}
}


private addAuthHeader(requestParams: IRequestParams) {
if (!requestParams.headers) {
requestParams.headers = {};
Expand Down

0 comments on commit a8a2892

Please sign in to comment.