import Axios , { AxiosPromise , AxiosRequestConfig } from 'axios' ; import * as rax from 'retry-axios' ; import { logger } from '../logger' ; const DEFAULT_RETRY_CONFIG = { retry : 3 , noResponseRetries : 2 , onRetryAttempt : ( err ) => { const cfg = rax . getConfig ( err ) ; if ( cfg ) { logger . warn ( `HTTP retry attempt #${ cfg . currentRetryAttempt }. ${ err . message }` ) ; } else { logger . warn ( `HTTP retry. ${ err . message }` ) ; } } , } ; const retryableAxiosInstance = Axios . create ( ) ; export const retryableAxios = ( config ) : AxiosPromise => { return retryableAxiosInstance ( { ... config , raxConfig : { instance : retryableAxiosInstance , ... DEFAULT_RETRY_CONFIG , ... config . raxConfig , } , } ) ; } ; rax . attach ( retryableAxiosInstance ) ;