Skip to content

Commit

Permalink
Added handling for when we have network failures in the retry mechani…
Browse files Browse the repository at this point in the history
…sm (#223)

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

* forgot ";'

* Fixed to be proper version

* .
  • Loading branch information
mastrzyz committed Jun 30, 2020
1 parent f8d4424 commit 06d0fc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion 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
@@ -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": {
Expand Down

0 comments on commit 06d0fc1

Please sign in to comment.