@telstra/core
Version:
Telstra SDK Core
82 lines (81 loc) • 2.53 kB
TypeScript
import { IAuthConfigProps } from '../../authentication/index.js';
import { IHttpClient } from '../index.js';
import { LoggerMixin } from '../../logging/impl/index.js';
import { AxiosInstance } from 'axios';
declare module 'axios' {
interface AxiosResponse<T = any> extends Promise<T> {
}
}
export declare abstract class HttpClient extends LoggerMixin implements IHttpClient {
protected readonly instance: AxiosInstance;
private readonly authManager;
private authRetryCount;
constructor(authConfig?: IAuthConfigProps);
private _initializeRequestInterceptor;
private _initializeResponseInterceptor;
/**
* @method _handleRequest
* @description Handles the request by adding the necessary headers and checking if the token is expired
* @param {AxiosRequestConfig} config
* @returns {Promise<AxiosRequestConfig>}
* @private
* @async
* @throws {MissingTokenDataError}
* @instance
*/
private _handleRequest;
/**
* @method _isTokenExpired
* @description Checks if the token is expired
* @param expires_at {Date} The date the token expires
* @returns {boolean} Returns a boolean value indicating whether the token is expired
* @private
* @async
* @instance
*/
private _isTokenExpired;
/**
* @method _handleRequestError
* @description Handles the request error
* @param {AxiosError} error
* @returns {Promise<AxiosError>}
* @private
* @instance
* @async
* @throws {AxiosError} The error that occurred during the request
*/
private _handleRequestError;
/**
* @method _handleResponse
* @description Handles the response
* @param {AxiosResponse} response
* @returns {AxiosResponse}
* @private
* @instance
* @async
*/
private _handleResponse;
/**
* @method _handleResponseError
* @description Handles the response error
* @param {AxiosError} error
* @returns {Promise<AxiosError>}
* @private
* @instance
* @async
* @throws {AxiosError} The error that occurred during the response
* @throws {MaxAuthRetryCountReachedError}
*/
private _handleResponseError;
/**
* @method _renewToken
* @description Renews the token data
* @param {IAuthCredentials} authCredentials
* @returns {Promise<IAuthTokenData>}
* @private
* @async
* @instance
* @throws {InvalidTokenError} Invalid token
*/
private _renewToken;
}