rxtutils 1.1.4-beta.10 → 1.1.4-beta.11
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/cjs/request/index.cjs +23 -9
- package/es/request/index.mjs +23 -9
- package/package.json +1 -1
package/cjs/request/index.cjs
CHANGED
|
@@ -35,6 +35,12 @@ function createBaseRequest(baseOptions) {
|
|
|
35
35
|
var cache = new index.default(cacheDataInStorage, cacheDataKey, cacheTime, indexDBName, cacheKeyEquals);
|
|
36
36
|
function request(requestParam, options) {
|
|
37
37
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
38
|
+
function retry() {
|
|
39
|
+
if (retryTimes > 0) {
|
|
40
|
+
return request(requestParam, tslib.__assign(tslib.__assign({}, options), { retryTimes: retryTimes - 1 }));
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
38
44
|
var _a, _b, requestMiddlewares, _c, finalAxiosOptions, finalRequestOptions, _i, requestMiddlewares_1, middleware, _d, nextAxiosOptions, nextRequestOptions, method, url, _e, data, _f, params, requestDataOrParams, _g, defaultMessageShower, _h, _j, enableCache, _k, cacheData, _l, defaultErrorCodeHandler, _m, defaultHttpErrorCodeHandler, _o, otherErrorHandler, _p, errorCodePath, _q, cacheTime, _r, errorCodeMap, _s, successCodes, _t, httpErrorCodeMap, _u,
|
|
39
45
|
// axiosOptions = {},
|
|
40
46
|
throwError, _v, retryTimes, cacheItem;
|
|
@@ -75,7 +81,7 @@ function createBaseRequest(baseOptions) {
|
|
|
75
81
|
return [2 /*return*/, instance
|
|
76
82
|
.request(tslib.__assign({ method: method, url: url, data: data, params: params }, finalAxiosOptions))
|
|
77
83
|
.then(function (res) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
78
|
-
var errorCode, _a, _b, _c, customHandler, err, _d, _e, replaceResData, _f, handlerThrowError, _g;
|
|
84
|
+
var errorCode, _a, _b, _c, customHandler, err, retryTask, _d, _e, replaceResData, _f, handlerThrowError, _g, retryTask;
|
|
79
85
|
return tslib.__generator(this, function (_h) {
|
|
80
86
|
switch (_h.label) {
|
|
81
87
|
case 0:
|
|
@@ -86,20 +92,22 @@ function createBaseRequest(baseOptions) {
|
|
|
86
92
|
}
|
|
87
93
|
return [2 /*return*/, res.data];
|
|
88
94
|
}
|
|
89
|
-
// 不在成功 code 中,意味着请求失败
|
|
90
|
-
if (retryTimes > 0) {
|
|
91
|
-
return [2 /*return*/, request(requestParam, tslib.__assign(tslib.__assign({}, options), { retryTimes: retryTimes - 1 }))];
|
|
92
|
-
}
|
|
93
95
|
_a = errorCodeMap, _b = errorCode, _c = _a[_b], customHandler = _c === void 0 ? defaultErrorCodeHandler : _c;
|
|
94
96
|
err = new error("服务端错误", "server", res);
|
|
95
97
|
if (!(typeof customHandler === "string")) return [3 /*break*/, 1];
|
|
96
98
|
defaultMessageShower(customHandler);
|
|
99
|
+
retryTask = retry();
|
|
100
|
+
if (retryTask)
|
|
101
|
+
return [2 /*return*/, retryTask];
|
|
97
102
|
return [3 /*break*/, 3];
|
|
98
103
|
case 1:
|
|
99
104
|
_g = Object;
|
|
100
105
|
return [4 /*yield*/, customHandler(errorCode, res.data, res, tslib.__assign(tslib.__assign({}, requestOptions), requestParam))];
|
|
101
106
|
case 2:
|
|
102
107
|
_d = _g.apply(void 0, [(_h.sent())]), _e = _d.replaceResData, replaceResData = _e === void 0 ? res.data : _e, _f = _d.throwError, handlerThrowError = _f === void 0 ? "default" : _f;
|
|
108
|
+
retryTask = retry();
|
|
109
|
+
if (retryTask)
|
|
110
|
+
return [2 /*return*/, retryTask];
|
|
103
111
|
res.data = replaceResData;
|
|
104
112
|
switch (handlerThrowError) {
|
|
105
113
|
case true:
|
|
@@ -116,25 +124,28 @@ function createBaseRequest(baseOptions) {
|
|
|
116
124
|
}
|
|
117
125
|
});
|
|
118
126
|
}); }, function (error$1) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
119
|
-
var resData, _a, _b, _c, customHandler, err, _d, _e, replaceResData, _f, handlerThrowError, _g, resData, err, _h, _j, replaceResData, _k, handlerThrowError, _l;
|
|
127
|
+
var resData, _a, _b, _c, customHandler, err, retryTask, _d, _e, replaceResData, _f, handlerThrowError, _g, retryTask, resData, err, _h, _j, replaceResData, _k, handlerThrowError, _l, retryTask;
|
|
120
128
|
return tslib.__generator(this, function (_m) {
|
|
121
129
|
switch (_m.label) {
|
|
122
130
|
case 0:
|
|
123
|
-
if (retryTimes > 0) {
|
|
124
|
-
return [2 /*return*/, request(requestParam, tslib.__assign(tslib.__assign({}, options), { retryTimes: retryTimes - 1 }))];
|
|
125
|
-
}
|
|
126
131
|
if (!error$1.response) return [3 /*break*/, 4];
|
|
127
132
|
resData = error$1;
|
|
128
133
|
_a = httpErrorCodeMap, _b = error$1.response.status, _c = _a[_b], customHandler = _c === void 0 ? defaultHttpErrorCodeHandler : _c;
|
|
129
134
|
err = new error("服务端错误", "http", error$1);
|
|
130
135
|
if (!(typeof customHandler === "string")) return [3 /*break*/, 1];
|
|
131
136
|
defaultMessageShower(customHandler);
|
|
137
|
+
retryTask = retry();
|
|
138
|
+
if (retryTask)
|
|
139
|
+
return [2 /*return*/, retryTask];
|
|
132
140
|
return [3 /*break*/, 3];
|
|
133
141
|
case 1:
|
|
134
142
|
_g = Object;
|
|
135
143
|
return [4 /*yield*/, customHandler(error$1.response.status, error$1, tslib.__assign(tslib.__assign({}, requestOptions), requestParam))];
|
|
136
144
|
case 2:
|
|
137
145
|
_d = _g.apply(void 0, [(_m.sent())]), _e = _d.replaceResData, replaceResData = _e === void 0 ? error$1 : _e, _f = _d.throwError, handlerThrowError = _f === void 0 ? "default" : _f;
|
|
146
|
+
retryTask = retry();
|
|
147
|
+
if (retryTask)
|
|
148
|
+
return [2 /*return*/, retryTask];
|
|
138
149
|
resData = replaceResData;
|
|
139
150
|
switch (handlerThrowError) {
|
|
140
151
|
case true:
|
|
@@ -157,6 +168,9 @@ function createBaseRequest(baseOptions) {
|
|
|
157
168
|
return [4 /*yield*/, otherErrorHandler(error$1)];
|
|
158
169
|
case 5:
|
|
159
170
|
_h = (_l.apply(void 0, [(_m.sent())])), _j = _h.replaceResData, replaceResData = _j === void 0 ? error$1 : _j, _k = _h.throwError, handlerThrowError = _k === void 0 ? "default" : _k;
|
|
171
|
+
retryTask = retry();
|
|
172
|
+
if (retryTask)
|
|
173
|
+
return [2 /*return*/, retryTask];
|
|
160
174
|
resData = replaceResData;
|
|
161
175
|
switch (handlerThrowError) {
|
|
162
176
|
case true:
|
package/es/request/index.mjs
CHANGED
|
@@ -33,6 +33,12 @@ function createBaseRequest(baseOptions) {
|
|
|
33
33
|
var cache = new Cache(cacheDataInStorage, cacheDataKey, cacheTime, indexDBName, cacheKeyEquals);
|
|
34
34
|
function request(requestParam, options) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function () {
|
|
36
|
+
function retry() {
|
|
37
|
+
if (retryTimes > 0) {
|
|
38
|
+
return request(requestParam, __assign(__assign({}, options), { retryTimes: retryTimes - 1 }));
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
36
42
|
var _a, _b, requestMiddlewares, _c, finalAxiosOptions, finalRequestOptions, _i, requestMiddlewares_1, middleware, _d, nextAxiosOptions, nextRequestOptions, method, url, _e, data, _f, params, requestDataOrParams, _g, defaultMessageShower, _h, _j, enableCache, _k, cacheData, _l, defaultErrorCodeHandler, _m, defaultHttpErrorCodeHandler, _o, otherErrorHandler, _p, errorCodePath, _q, cacheTime, _r, errorCodeMap, _s, successCodes, _t, httpErrorCodeMap, _u,
|
|
37
43
|
// axiosOptions = {},
|
|
38
44
|
throwError, _v, retryTimes, cacheItem;
|
|
@@ -73,7 +79,7 @@ function createBaseRequest(baseOptions) {
|
|
|
73
79
|
return [2 /*return*/, instance
|
|
74
80
|
.request(__assign({ method: method, url: url, data: data, params: params }, finalAxiosOptions))
|
|
75
81
|
.then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
76
|
-
var errorCode, _a, _b, _c, customHandler, err, _d, _e, replaceResData, _f, handlerThrowError, _g;
|
|
82
|
+
var errorCode, _a, _b, _c, customHandler, err, retryTask, _d, _e, replaceResData, _f, handlerThrowError, _g, retryTask;
|
|
77
83
|
return __generator(this, function (_h) {
|
|
78
84
|
switch (_h.label) {
|
|
79
85
|
case 0:
|
|
@@ -84,20 +90,22 @@ function createBaseRequest(baseOptions) {
|
|
|
84
90
|
}
|
|
85
91
|
return [2 /*return*/, res.data];
|
|
86
92
|
}
|
|
87
|
-
// 不在成功 code 中,意味着请求失败
|
|
88
|
-
if (retryTimes > 0) {
|
|
89
|
-
return [2 /*return*/, request(requestParam, __assign(__assign({}, options), { retryTimes: retryTimes - 1 }))];
|
|
90
|
-
}
|
|
91
93
|
_a = errorCodeMap, _b = errorCode, _c = _a[_b], customHandler = _c === void 0 ? defaultErrorCodeHandler : _c;
|
|
92
94
|
err = new RequestError("服务端错误", "server", res);
|
|
93
95
|
if (!(typeof customHandler === "string")) return [3 /*break*/, 1];
|
|
94
96
|
defaultMessageShower(customHandler);
|
|
97
|
+
retryTask = retry();
|
|
98
|
+
if (retryTask)
|
|
99
|
+
return [2 /*return*/, retryTask];
|
|
95
100
|
return [3 /*break*/, 3];
|
|
96
101
|
case 1:
|
|
97
102
|
_g = Object;
|
|
98
103
|
return [4 /*yield*/, customHandler(errorCode, res.data, res, __assign(__assign({}, requestOptions), requestParam))];
|
|
99
104
|
case 2:
|
|
100
105
|
_d = _g.apply(void 0, [(_h.sent())]), _e = _d.replaceResData, replaceResData = _e === void 0 ? res.data : _e, _f = _d.throwError, handlerThrowError = _f === void 0 ? "default" : _f;
|
|
106
|
+
retryTask = retry();
|
|
107
|
+
if (retryTask)
|
|
108
|
+
return [2 /*return*/, retryTask];
|
|
101
109
|
res.data = replaceResData;
|
|
102
110
|
switch (handlerThrowError) {
|
|
103
111
|
case true:
|
|
@@ -114,25 +122,28 @@ function createBaseRequest(baseOptions) {
|
|
|
114
122
|
}
|
|
115
123
|
});
|
|
116
124
|
}); }, function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
117
|
-
var resData, _a, _b, _c, customHandler, err, _d, _e, replaceResData, _f, handlerThrowError, _g, resData, err, _h, _j, replaceResData, _k, handlerThrowError, _l;
|
|
125
|
+
var resData, _a, _b, _c, customHandler, err, retryTask, _d, _e, replaceResData, _f, handlerThrowError, _g, retryTask, resData, err, _h, _j, replaceResData, _k, handlerThrowError, _l, retryTask;
|
|
118
126
|
return __generator(this, function (_m) {
|
|
119
127
|
switch (_m.label) {
|
|
120
128
|
case 0:
|
|
121
|
-
if (retryTimes > 0) {
|
|
122
|
-
return [2 /*return*/, request(requestParam, __assign(__assign({}, options), { retryTimes: retryTimes - 1 }))];
|
|
123
|
-
}
|
|
124
129
|
if (!error.response) return [3 /*break*/, 4];
|
|
125
130
|
resData = error;
|
|
126
131
|
_a = httpErrorCodeMap, _b = error.response.status, _c = _a[_b], customHandler = _c === void 0 ? defaultHttpErrorCodeHandler : _c;
|
|
127
132
|
err = new RequestError("服务端错误", "http", error);
|
|
128
133
|
if (!(typeof customHandler === "string")) return [3 /*break*/, 1];
|
|
129
134
|
defaultMessageShower(customHandler);
|
|
135
|
+
retryTask = retry();
|
|
136
|
+
if (retryTask)
|
|
137
|
+
return [2 /*return*/, retryTask];
|
|
130
138
|
return [3 /*break*/, 3];
|
|
131
139
|
case 1:
|
|
132
140
|
_g = Object;
|
|
133
141
|
return [4 /*yield*/, customHandler(error.response.status, error, __assign(__assign({}, requestOptions), requestParam))];
|
|
134
142
|
case 2:
|
|
135
143
|
_d = _g.apply(void 0, [(_m.sent())]), _e = _d.replaceResData, replaceResData = _e === void 0 ? error : _e, _f = _d.throwError, handlerThrowError = _f === void 0 ? "default" : _f;
|
|
144
|
+
retryTask = retry();
|
|
145
|
+
if (retryTask)
|
|
146
|
+
return [2 /*return*/, retryTask];
|
|
136
147
|
resData = replaceResData;
|
|
137
148
|
switch (handlerThrowError) {
|
|
138
149
|
case true:
|
|
@@ -155,6 +166,9 @@ function createBaseRequest(baseOptions) {
|
|
|
155
166
|
return [4 /*yield*/, otherErrorHandler(error)];
|
|
156
167
|
case 5:
|
|
157
168
|
_h = (_l.apply(void 0, [(_m.sent())])), _j = _h.replaceResData, replaceResData = _j === void 0 ? error : _j, _k = _h.throwError, handlerThrowError = _k === void 0 ? "default" : _k;
|
|
169
|
+
retryTask = retry();
|
|
170
|
+
if (retryTask)
|
|
171
|
+
return [2 /*return*/, retryTask];
|
|
158
172
|
resData = replaceResData;
|
|
159
173
|
switch (handlerThrowError) {
|
|
160
174
|
case true:
|