@whitesev/utils 1.4.8 → 1.5.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/index.amd.js +55 -14
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +55 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +55 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +55 -14
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +55 -14
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +55 -14
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +13 -1
- package/package.json +1 -1
- package/src/Httpx.ts +80 -21
package/dist/index.amd.js
CHANGED
|
@@ -1463,7 +1463,7 @@ define((function () { 'use strict';
|
|
|
1463
1463
|
/**
|
|
1464
1464
|
* 添加请求前的回调处理配置
|
|
1465
1465
|
*/
|
|
1466
|
-
|
|
1466
|
+
add(fn) {
|
|
1467
1467
|
if (typeof fn === "function") {
|
|
1468
1468
|
let uuid = GenerateUUID();
|
|
1469
1469
|
this.$config.configList.push({
|
|
@@ -1480,7 +1480,7 @@ define((function () { 'use strict';
|
|
|
1480
1480
|
* 删除请求前的回调处理配置
|
|
1481
1481
|
* @param id
|
|
1482
1482
|
*/
|
|
1483
|
-
|
|
1483
|
+
delete(id) {
|
|
1484
1484
|
if (typeof id === "string") {
|
|
1485
1485
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1486
1486
|
if (findIndex !== -1) {
|
|
@@ -1493,7 +1493,7 @@ define((function () { 'use strict';
|
|
|
1493
1493
|
/**
|
|
1494
1494
|
* 清空设置的请求前的回调处理配置
|
|
1495
1495
|
*/
|
|
1496
|
-
|
|
1496
|
+
clearAll() {
|
|
1497
1497
|
this.$config.configList = [];
|
|
1498
1498
|
},
|
|
1499
1499
|
};
|
|
@@ -1523,21 +1523,21 @@ define((function () { 'use strict';
|
|
|
1523
1523
|
* 失败的回调
|
|
1524
1524
|
* @param response
|
|
1525
1525
|
*/
|
|
1526
|
-
errorResponseCallBack(
|
|
1526
|
+
errorResponseCallBack(data) {
|
|
1527
1527
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1528
1528
|
let item = this.$config.configList[index];
|
|
1529
1529
|
if (typeof item.errorFn === "function") {
|
|
1530
|
-
if (item.errorFn(
|
|
1530
|
+
if (item.errorFn(data) == null) {
|
|
1531
1531
|
return;
|
|
1532
1532
|
}
|
|
1533
1533
|
}
|
|
1534
1534
|
}
|
|
1535
|
-
return
|
|
1535
|
+
return data;
|
|
1536
1536
|
},
|
|
1537
1537
|
/**
|
|
1538
1538
|
* 添加请求前的回调处理配置
|
|
1539
1539
|
*/
|
|
1540
|
-
|
|
1540
|
+
add(successFn, errorFn) {
|
|
1541
1541
|
let id = GenerateUUID();
|
|
1542
1542
|
this.$config.configList.push({
|
|
1543
1543
|
id: id,
|
|
@@ -1550,7 +1550,7 @@ define((function () { 'use strict';
|
|
|
1550
1550
|
* 删除请求前的回调处理配置
|
|
1551
1551
|
* @param id
|
|
1552
1552
|
*/
|
|
1553
|
-
|
|
1553
|
+
delete(id) {
|
|
1554
1554
|
if (typeof id === "string") {
|
|
1555
1555
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1556
1556
|
if (findIndex !== -1) {
|
|
@@ -1563,7 +1563,7 @@ define((function () { 'use strict';
|
|
|
1563
1563
|
/**
|
|
1564
1564
|
* 清空设置的请求前的回调处理配置
|
|
1565
1565
|
*/
|
|
1566
|
-
|
|
1566
|
+
clearAll() {
|
|
1567
1567
|
this.$config.configList = [];
|
|
1568
1568
|
},
|
|
1569
1569
|
};
|
|
@@ -1780,6 +1780,13 @@ define((function () { 'use strict';
|
|
|
1780
1780
|
else if ("onabort" in this.context.#defaultDetails) {
|
|
1781
1781
|
this.context.#defaultDetails.onabort.apply(this, argumentsList);
|
|
1782
1782
|
}
|
|
1783
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1784
|
+
type: "onabort",
|
|
1785
|
+
error: new TypeError("request canceled"),
|
|
1786
|
+
response: null,
|
|
1787
|
+
}) == null) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1783
1790
|
resolve({
|
|
1784
1791
|
status: false,
|
|
1785
1792
|
data: [...argumentsList],
|
|
@@ -1804,6 +1811,13 @@ define((function () { 'use strict';
|
|
|
1804
1811
|
if (response.length) {
|
|
1805
1812
|
response = response[0];
|
|
1806
1813
|
}
|
|
1814
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1815
|
+
type: "onerror",
|
|
1816
|
+
error: new TypeError("request error"),
|
|
1817
|
+
response: response,
|
|
1818
|
+
}) == null) {
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1807
1821
|
resolve({
|
|
1808
1822
|
status: false,
|
|
1809
1823
|
data: response,
|
|
@@ -1825,6 +1839,13 @@ define((function () { 'use strict';
|
|
|
1825
1839
|
else if ("ontimeout" in this.context.#defaultDetails) {
|
|
1826
1840
|
this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
|
|
1827
1841
|
}
|
|
1842
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1843
|
+
type: "ontimeout",
|
|
1844
|
+
error: new TypeError("request timeout"),
|
|
1845
|
+
response: (argumentsList || [null])[0],
|
|
1846
|
+
}) == null) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1828
1849
|
resolve({
|
|
1829
1850
|
status: false,
|
|
1830
1851
|
data: [...argumentsList],
|
|
@@ -1905,6 +1926,10 @@ define((function () { 'use strict';
|
|
|
1905
1926
|
}
|
|
1906
1927
|
/* 状态码2xx都是成功的 */
|
|
1907
1928
|
if (Math.floor(Response.status / 100) === 2) {
|
|
1929
|
+
if (this.context.HttpxResponseHook.successResponseCallBack(Response) ==
|
|
1930
|
+
null) {
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1908
1933
|
resolve({
|
|
1909
1934
|
status: true,
|
|
1910
1935
|
data: Response,
|
|
@@ -2153,14 +2178,24 @@ define((function () { 'use strict';
|
|
|
2153
2178
|
* @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
|
|
2154
2179
|
*/
|
|
2155
2180
|
use(fn) {
|
|
2156
|
-
|
|
2181
|
+
if (typeof fn !== "function") {
|
|
2182
|
+
console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
return this.context.HttpxRequestHook.add(fn);
|
|
2157
2186
|
},
|
|
2158
2187
|
/**
|
|
2159
2188
|
* 移除拦截器
|
|
2160
2189
|
* @param id 通过use返回的id
|
|
2161
2190
|
*/
|
|
2162
2191
|
eject(id) {
|
|
2163
|
-
return this.context.HttpxRequestHook.
|
|
2192
|
+
return this.context.HttpxRequestHook.delete(id);
|
|
2193
|
+
},
|
|
2194
|
+
/**
|
|
2195
|
+
* 移除所有拦截器
|
|
2196
|
+
*/
|
|
2197
|
+
ejectAll() {
|
|
2198
|
+
this.context.HttpxRequestHook.clearAll();
|
|
2164
2199
|
},
|
|
2165
2200
|
},
|
|
2166
2201
|
/**
|
|
@@ -2177,17 +2212,23 @@ define((function () { 'use strict';
|
|
|
2177
2212
|
*/
|
|
2178
2213
|
use(successFn, errorFn) {
|
|
2179
2214
|
if (typeof successFn !== "function" && typeof errorFn !== "function") {
|
|
2180
|
-
console.warn("[Httpx]
|
|
2215
|
+
console.warn("[Httpx-interceptors-response] 必须传入一个拦截器函数");
|
|
2181
2216
|
return;
|
|
2182
2217
|
}
|
|
2183
|
-
return this.context.HttpxResponseHook.
|
|
2218
|
+
return this.context.HttpxResponseHook.add(successFn, errorFn);
|
|
2184
2219
|
},
|
|
2185
2220
|
/**
|
|
2186
2221
|
* 移除拦截器
|
|
2187
2222
|
* @param id 通过use返回的id
|
|
2188
2223
|
*/
|
|
2189
2224
|
eject(id) {
|
|
2190
|
-
return this.context.HttpxResponseHook.
|
|
2225
|
+
return this.context.HttpxResponseHook.delete(id);
|
|
2226
|
+
},
|
|
2227
|
+
/**
|
|
2228
|
+
* 移除所有拦截器
|
|
2229
|
+
*/
|
|
2230
|
+
ejectAll() {
|
|
2231
|
+
this.context.HttpxResponseHook.clearAll();
|
|
2191
2232
|
},
|
|
2192
2233
|
},
|
|
2193
2234
|
};
|