chore: upgrade got (#14913)

* chore: upgrade got

* fix: new got
This commit is contained in:
DIYgod
2024-03-22 22:42:29 +08:00
committed by GitHub
parent 2ed8e87a4d
commit 2789ed96e5
5 changed files with 392 additions and 439 deletions
+5 -13
View File
@@ -1,6 +1,6 @@
import logger from '@/utils/logger';
import { config } from '@/config';
import got, { CancelableRequest, Response as GotResponse, NormalizedOptions, Options, Got } from 'got';
import got, { CancelableRequest, Response as GotResponse, OptionsInit, Options, Got } from 'got';
type Response<T> = GotResponse<string> & {
data: T;
@@ -25,22 +25,14 @@ const custom: {
delete: GotRequestFunction;
} & GotRequestFunction &
Got = got.extend({
get: got.get,
retry: {
limit: config.requestRetry,
statusCodes: [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511, 521, 522, 524],
},
hooks: {
beforeRetry: [
(
options: NormalizedOptions & {
retryCount?: number;
},
err,
count
) => {
logger.error(`Request ${options.url} fail, retry attempt #${count}: ${err}`);
options.retryCount = count;
(err, count) => {
logger.error(`Request ${err.options.url} fail, retry attempt #${count}: ${err}`);
},
],
beforeRedirect: [
@@ -63,7 +55,7 @@ const custom: {
],
init: [
(
options: Options & {
options: OptionsInit & {
data?: string;
}
) => {
@@ -84,4 +76,4 @@ const custom: {
custom.all = (list) => Promise.all(list);
export default custom;
export type { Response, NormalizedOptions, Options } from 'got';
export type { Response, Options } from 'got';
+1
View File
@@ -45,6 +45,7 @@ const requestWrapper = (url: string, options: http.RequestOptions = {}) => {
if (config.proxyStrategy === 'all') {
prxied = proxyWrapper(url, optionsWithHeaders);
} else if (config.proxyStrategy === 'on_retry' && (optionsWithHeaders as any).retryCount) {
// TODO
prxied = proxyWrapper(url, optionsWithHeaders);
}
if (prxied) {