deno.land / x / ky@v0.31.3 / source / utils / normalize.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {requestMethods} from '../core/constants.js';import type {HttpMethod} from '../types/options.js';import type {RetryOptions} from '../types/retry.js';
export const normalizeRequestMethod = (input: string): string => requestMethods.includes(input as HttpMethod) ? input.toUpperCase() : input;
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
const retryAfterStatusCodes = [413, 429, 503];
const defaultRetryOptions: Required<RetryOptions> = { limit: 2, methods: retryMethods, statusCodes: retryStatusCodes, afterStatusCodes: retryAfterStatusCodes, maxRetryAfter: Number.POSITIVE_INFINITY,};
export const normalizeRetryOptions = (retry: number | RetryOptions = {}): Required<RetryOptions> => { 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, afterStatusCodes: retryAfterStatusCodes, };};
ky

Version Info

Tagged at
a year ago