Added handling for when we have network failures in the retry mechanism (#223)

* Added handling for when we have network failures in the retry mechanism

* forgot ";'

* Fixed to be proper version

* .
This commit is contained in:
Marcin Strzyz 2020-06-30 13:05:39 -07:00 коммит произвёл GitHub
Родитель f8d4424872
Коммит 06d0fc1eae
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -41,6 +41,7 @@ export enum HttpCodes {
const HttpRedirectCodes: number[] = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
const HttpResponseRetryCodes: number[] = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
const NetworkRetryErrors: string[] = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED'];
const RetryableHttpVerbs: string[] = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
const ExponentialBackoffCeiling = 10;
const ExponentialBackoffTimeSlice = 5;
@ -243,8 +244,15 @@ export class HttpClient implements ifm.IHttpClient {
let response: HttpClientResponse;
while (numTries < maxTries) {
response = await this.requestRaw(info, data);
try{
response = await this.requestRaw(info, data);
}
catch (err) {
if(err && err.code && NetworkRetryErrors.indexOf(err.code) > -1){
continue;
}
throw err;
}
// Check if it's an authentication challenge
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
let authenticationHandler: ifm.IRequestHandler;

2
package-lock.json сгенерированный
Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "typed-rest-client",
"version": "1.7.3",
"version": "1.8.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "typed-rest-client",
"version": "1.7.3",
"version": "1.8.0",
"description": "Node Rest and Http Clients for use with TypeScript",
"main": "./RestClient.js",
"scripts": {