Skip to content

Commit

Permalink
Merge 1c9f9fe into e22a303
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Feb 28, 2020
2 parents e22a303 + 1c9f9fe commit 1c1f6cb
Show file tree
Hide file tree
Showing 50 changed files with 2,602 additions and 2,491 deletions.
25 changes: 12 additions & 13 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"node": ">=10"
},
"scripts": {
"test": "xo && tsc --noEmit && nyc ava",
"test": "xo && tsc --noEmit && nyc --reporter=html --reporter=text ava",
"release": "np",
"build": "del-cli dist && tsc",
"prepare": "npm run build"
Expand All @@ -33,29 +33,27 @@
"fetch",
"net",
"network",
"electron",
"gzip",
"brotli",
"requests",
"human-friendly",
"axios",
"superagent"
"superagent",
"node-fetch",
"ky"
],
"dependencies": {
"@sindresorhus/is": "^2.0.0",
"@sindresorhus/is": "^2.1.0",
"@szmarczak/http-timer": "^4.0.0",
"@types/cacheable-request": "^6.0.1",
"cacheable-lookup": "^2.0.0",
"cacheable-lookup": "^3.0.0",
"cacheable-request": "^7.0.1",
"decompress-response": "^5.0.0",
"duplexer3": "^0.1.4",
"get-stream": "^5.0.0",
"http2-wrapper": "^1.0.0-beta.4.2",
"lowercase-keys": "^2.0.0",
"mimic-response": "^2.1.0",
"p-cancelable": "^2.0.0",
"p-event": "^4.0.0",
"responselike": "^2.0.0",
"to-readable-stream": "^2.0.0",
"type-fest": "^0.10.0"
"responselike": "^2.0.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
Expand Down Expand Up @@ -83,19 +81,20 @@
"nock": "^12.0.0",
"np": "^6.0.0",
"nyc": "^15.0.0",
"p-event": "^4.0.0",
"proxyquire": "^2.0.1",
"sinon": "^8.1.1",
"slow-stream": "0.0.4",
"tempy": "^0.4.0",
"to-readable-stream": "^2.1.0",
"tough-cookie": "^3.0.0",
"typescript": "3.7.5",
"xo": "^0.26.0"
},
"types": "dist/source",
"sideEffects": false,
"browser": {
"decompress-response": false,
"electron": false
"decompress-response": false
},
"ava": {
"files": [
Expand Down
182 changes: 0 additions & 182 deletions source/as-promise.ts

This file was deleted.

@@ -1,6 +1,10 @@
import is from '@sindresorhus/is';
import {HTTPError, ParseError, MaxRedirectsError} from './errors';
import {RetryFunction, RetryObject} from './types';
import {
ParseError,
HTTPError,
MaxRedirectsError,
RetryObject,
RetryFunction
} from './types';

const retryAfterStatusCodes: ReadonlySet<number> = new Set([413, 429, 503]);

Expand All @@ -14,23 +18,23 @@ const calculateRetryDelay: RetryFunction = ({attemptCount, retryOptions, error})
}

const hasMethod = retryOptions.methods.includes(error.options.method);
const hasErrorCode = Reflect.has(error, 'code') && retryOptions.errorCodes.includes(error.code);
const hasErrorCode = retryOptions.errorCodes.includes(error.code!);
const hasStatusCode = isErrorWithResponse(error) && retryOptions.statusCodes.includes(error.response.statusCode);
if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
return 0;
}

if (isErrorWithResponse(error)) {
const {response} = error;
if (response && Reflect.has(response.headers, 'retry-after') && retryAfterStatusCodes.has(response.statusCode)) {
if (response && 'retry-after' in response.headers && retryAfterStatusCodes.has(response.statusCode)) {
let after = Number(response.headers['retry-after']);
if (is.nan(after)) {
if (isNaN(after)) {
after = Date.parse(response.headers['retry-after']!) - Date.now();
} else {
after *= 1000;
}

if (after > retryOptions.maxRetryAfter) {
if (retryOptions.maxRetryAfter === undefined || after > retryOptions.maxRetryAfter) {
return 0;
}

Expand Down

0 comments on commit 1c1f6cb

Please sign in to comment.