@aircall/http
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.4.3](http://bitbucket.org/aircall/front-end-modules/compare/@aircall/http@0.4.2...@aircall/http@0.4.3) (2021-06-04) | ||
**Note:** Version bump only for package @aircall/http | ||
## [0.4.2](http://bitbucket.org/aircall/front-end-modules/compare/@aircall/http@0.4.1...@aircall/http@0.4.2) (2021-05-10) | ||
@@ -8,0 +16,0 @@ |
@@ -7,1 +7,2 @@ export declare enum ErrorCode { | ||
export declare const DEFAULT_MAX_RETRY = 3; | ||
export declare const DEFAULT_DELAY = 300; |
@@ -12,2 +12,4 @@ "use strict"; | ||
exports.DEFAULT_MAX_RETRY = 3; | ||
// Delay of 300ms will be applied between each retry | ||
exports.DEFAULT_DELAY = 300; | ||
//# sourceMappingURL=constants.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const utils_1 = require("./utils"); | ||
/* istanbul ignore next */ | ||
@@ -71,3 +72,3 @@ function defaultRetryCondition() { | ||
} | ||
const { onRetryAttempt = noop, retryCondition = defaultRetryCondition, maxRetry = constants_1.DEFAULT_MAX_RETRY } = retryStrategy; | ||
const { onRetryAttempt = noop, retryCondition = defaultRetryCondition, maxRetry = constants_1.DEFAULT_MAX_RETRY, delay = constants_1.DEFAULT_DELAY } = retryStrategy; | ||
const { config } = error; | ||
@@ -78,2 +79,5 @@ config.retryCount = (_a = config.retryCount) !== null && _a !== void 0 ? _a : 0; | ||
config.retryCount++; | ||
if (delay > 0) { | ||
await utils_1.sleep(delay); | ||
} | ||
await onRetryAttempt(error); | ||
@@ -80,0 +84,0 @@ return this.axiosInstance.request(error.config); |
@@ -25,4 +25,5 @@ import { AxiosRequestConfig, AxiosError } from 'axios'; | ||
onRetryAttempt?: <T extends HttpError>(error: T) => Promise<any>; | ||
delay?: number; | ||
}; | ||
} | ||
export {}; |
{ | ||
"name": "@aircall/http", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"main": "dist/index.js", | ||
@@ -14,3 +14,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "3441071ad789b88af3127571212f34ac07c61067", | ||
"gitHead": "2b86630b9b84788f7083b7694f286c395568aae0", | ||
"dependencies": { | ||
@@ -17,0 +17,0 @@ "@aircall/logger": "^2.5.2", |
@@ -11,1 +11,3 @@ export enum ErrorCode { | ||
export const DEFAULT_MAX_RETRY = 3; | ||
// Delay of 300ms will be applied between each retry | ||
export const DEFAULT_DELAY = 300; |
@@ -5,3 +5,4 @@ import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { HttpServiceOptions, RequestLogPayload, HTTP_LOG_TYPE } from './typing/HttpService'; | ||
import { DEFAULT_MAX_RETRY } from './constants'; | ||
import { DEFAULT_DELAY, DEFAULT_MAX_RETRY } from './constants'; | ||
import { sleep } from './utils'; | ||
@@ -160,2 +161,3 @@ /* istanbul ignore next */ | ||
const { retryStrategy } = this.options; | ||
if (!retryStrategy) { | ||
@@ -168,3 +170,4 @@ return Promise.reject(error); | ||
retryCondition = defaultRetryCondition, | ||
maxRetry = DEFAULT_MAX_RETRY | ||
maxRetry = DEFAULT_MAX_RETRY, | ||
delay = DEFAULT_DELAY | ||
} = retryStrategy; | ||
@@ -178,4 +181,7 @@ | ||
config.retryCount++; | ||
if (delay > 0) { | ||
await sleep(delay); | ||
} | ||
await onRetryAttempt(error); | ||
return this.axiosInstance.request(error.config); | ||
@@ -182,0 +188,0 @@ } |
@@ -28,3 +28,6 @@ import { AxiosRequestConfig, AxiosError } from 'axios'; | ||
onRetryAttempt?: <T extends HttpError>(error: T) => Promise<any>; | ||
// Delay between each retry. | ||
// Zero means that no delay will be applied | ||
delay?: number; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40399
24
759