got 11.5.2 → 11.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/source/as-promise/index.d.ts +1 -3
- package/dist/source/as-promise/index.js +44 -125
- package/dist/source/as-promise/normalize-arguments.d.ts +3 -0
- package/dist/source/as-promise/normalize-arguments.js +78 -0
- package/dist/source/as-promise/parse-body.d.ts +3 -0
- package/dist/source/as-promise/parse-body.js +25 -0
- package/dist/source/as-promise/types.d.ts +206 -24
- package/dist/source/as-promise/types.js +18 -7
- package/dist/source/{as-promise → core}/calculate-retry-delay.d.ts +2 -1
- package/dist/source/core/calculate-retry-delay.js +29 -0
- package/dist/source/core/index.d.ts +822 -5
- package/dist/source/core/index.js +198 -39
- package/dist/source/core/utils/is-response-ok.d.ts +2 -0
- package/dist/source/core/utils/is-response-ok.js +8 -0
- package/dist/source/create.js +16 -7
- package/dist/source/index.js +3 -2
- package/dist/source/types.d.ts +240 -1
- package/package.json +20 -16
- package/readme.md +75 -7
- package/dist/source/as-promise/calculate-retry-delay.js +0 -38
- package/dist/source/as-promise/core.d.ts +0 -13
- package/dist/source/as-promise/core.js +0 -127
|
@@ -7,23 +7,34 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.CancelError = exports.ParseError = void 0;
|
|
14
|
-
const p_cancelable_1 = require("p-cancelable");
|
|
15
|
-
Object.defineProperty(exports, "CancelError", { enumerable: true, get: function () { return p_cancelable_1.CancelError; } });
|
|
16
14
|
const core_1 = require("../core");
|
|
15
|
+
/**
|
|
16
|
+
An error to be thrown when server response code is 2xx, and parsing body fails.
|
|
17
|
+
Includes a `response` property.
|
|
18
|
+
*/
|
|
17
19
|
class ParseError extends core_1.RequestError {
|
|
18
20
|
constructor(error, response) {
|
|
19
21
|
const { options } = response.request;
|
|
20
22
|
super(`${error.message} in "${options.url.toString()}"`, error, response.request);
|
|
21
23
|
this.name = 'ParseError';
|
|
22
|
-
Object.defineProperty(this, 'response', {
|
|
23
|
-
enumerable: false,
|
|
24
|
-
value: response
|
|
25
|
-
});
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
exports.ParseError = ParseError;
|
|
27
|
+
/**
|
|
28
|
+
An error to be thrown when the request is aborted with `.cancel()`.
|
|
29
|
+
*/
|
|
30
|
+
class CancelError extends core_1.RequestError {
|
|
31
|
+
constructor(request) {
|
|
32
|
+
super('Promise was canceled', {}, request);
|
|
33
|
+
this.name = 'CancelError';
|
|
34
|
+
}
|
|
35
|
+
get isCanceled() {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.CancelError = CancelError;
|
|
29
40
|
__exportStar(require("../core"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RetryFunction } from '
|
|
1
|
+
import { RetryFunction } from '.';
|
|
2
2
|
declare type Returns<T extends (...args: any) => unknown, V> = (...args: Parameters<T>) => V;
|
|
3
|
+
export declare const retryAfterStatusCodes: ReadonlySet<number>;
|
|
3
4
|
declare const calculateRetryDelay: Returns<RetryFunction, number>;
|
|
4
5
|
export default calculateRetryDelay;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryAfterStatusCodes = void 0;
|
|
4
|
+
exports.retryAfterStatusCodes = new Set([413, 429, 503]);
|
|
5
|
+
const calculateRetryDelay = ({ attemptCount, retryOptions, error, retryAfter }) => {
|
|
6
|
+
if (attemptCount > retryOptions.limit) {
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
const hasMethod = retryOptions.methods.includes(error.options.method);
|
|
10
|
+
const hasErrorCode = retryOptions.errorCodes.includes(error.code);
|
|
11
|
+
const hasStatusCode = error.response && retryOptions.statusCodes.includes(error.response.statusCode);
|
|
12
|
+
if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
if (error.response) {
|
|
16
|
+
if (retryAfter) {
|
|
17
|
+
if (retryOptions.maxRetryAfter === undefined || retryAfter > retryOptions.maxRetryAfter) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
return retryAfter;
|
|
21
|
+
}
|
|
22
|
+
if (error.response.statusCode === 413) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const noise = Math.random() * 100;
|
|
27
|
+
return ((2 ** (attemptCount - 1)) * 1000) + noise;
|
|
28
|
+
};
|
|
29
|
+
exports.default = calculateRetryDelay;
|