@smeijer/ky
Version:
Tiny and elegant HTTP client based on the Fetch API
38 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeRetryOptions = exports.normalizeRequestMethod = void 0;
const constants_js_1 = require("../core/constants.js");
const normalizeRequestMethod = (input) => constants_js_1.requestMethods.includes(input) ? input.toUpperCase() : input;
exports.normalizeRequestMethod = normalizeRequestMethod;
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
const retryAfterStatusCodes = [413, 429, 503];
const defaultRetryOptions = {
limit: 2,
methods: retryMethods,
statusCodes: retryStatusCodes,
afterStatusCodes: retryAfterStatusCodes,
maxRetryAfter: Number.POSITIVE_INFINITY,
backoffLimit: Number.POSITIVE_INFINITY,
delay: attemptCount => 0.3 * (2 ** (attemptCount - 1)) * 1000,
};
const normalizeRetryOptions = (retry = {}) => {
if (typeof retry === 'number') {
return {
...defaultRetryOptions,
limit: retry,
};
}
if (retry.methods && !Array.isArray(retry.methods)) {
throw new Error('retry.methods must be an array');
}
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
throw new Error('retry.statusCodes must be an array');
}
return {
...defaultRetryOptions,
...retry,
};
};
exports.normalizeRetryOptions = normalizeRetryOptions;
//# sourceMappingURL=normalize.js.map