@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.system.js
CHANGED
|
@@ -1466,7 +1466,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1466
1466
|
/**
|
|
1467
1467
|
* 添加请求前的回调处理配置
|
|
1468
1468
|
*/
|
|
1469
|
-
|
|
1469
|
+
add(fn) {
|
|
1470
1470
|
if (typeof fn === "function") {
|
|
1471
1471
|
let uuid = GenerateUUID();
|
|
1472
1472
|
this.$config.configList.push({
|
|
@@ -1483,7 +1483,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1483
1483
|
* 删除请求前的回调处理配置
|
|
1484
1484
|
* @param id
|
|
1485
1485
|
*/
|
|
1486
|
-
|
|
1486
|
+
delete(id) {
|
|
1487
1487
|
if (typeof id === "string") {
|
|
1488
1488
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1489
1489
|
if (findIndex !== -1) {
|
|
@@ -1496,7 +1496,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1496
1496
|
/**
|
|
1497
1497
|
* 清空设置的请求前的回调处理配置
|
|
1498
1498
|
*/
|
|
1499
|
-
|
|
1499
|
+
clearAll() {
|
|
1500
1500
|
this.$config.configList = [];
|
|
1501
1501
|
},
|
|
1502
1502
|
};
|
|
@@ -1526,21 +1526,21 @@ System.register('Utils', [], (function (exports) {
|
|
|
1526
1526
|
* 失败的回调
|
|
1527
1527
|
* @param response
|
|
1528
1528
|
*/
|
|
1529
|
-
errorResponseCallBack(
|
|
1529
|
+
errorResponseCallBack(data) {
|
|
1530
1530
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1531
1531
|
let item = this.$config.configList[index];
|
|
1532
1532
|
if (typeof item.errorFn === "function") {
|
|
1533
|
-
if (item.errorFn(
|
|
1533
|
+
if (item.errorFn(data) == null) {
|
|
1534
1534
|
return;
|
|
1535
1535
|
}
|
|
1536
1536
|
}
|
|
1537
1537
|
}
|
|
1538
|
-
return
|
|
1538
|
+
return data;
|
|
1539
1539
|
},
|
|
1540
1540
|
/**
|
|
1541
1541
|
* 添加请求前的回调处理配置
|
|
1542
1542
|
*/
|
|
1543
|
-
|
|
1543
|
+
add(successFn, errorFn) {
|
|
1544
1544
|
let id = GenerateUUID();
|
|
1545
1545
|
this.$config.configList.push({
|
|
1546
1546
|
id: id,
|
|
@@ -1553,7 +1553,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1553
1553
|
* 删除请求前的回调处理配置
|
|
1554
1554
|
* @param id
|
|
1555
1555
|
*/
|
|
1556
|
-
|
|
1556
|
+
delete(id) {
|
|
1557
1557
|
if (typeof id === "string") {
|
|
1558
1558
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1559
1559
|
if (findIndex !== -1) {
|
|
@@ -1566,7 +1566,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1566
1566
|
/**
|
|
1567
1567
|
* 清空设置的请求前的回调处理配置
|
|
1568
1568
|
*/
|
|
1569
|
-
|
|
1569
|
+
clearAll() {
|
|
1570
1570
|
this.$config.configList = [];
|
|
1571
1571
|
},
|
|
1572
1572
|
};
|
|
@@ -1783,6 +1783,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
1783
1783
|
else if ("onabort" in this.context.#defaultDetails) {
|
|
1784
1784
|
this.context.#defaultDetails.onabort.apply(this, argumentsList);
|
|
1785
1785
|
}
|
|
1786
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1787
|
+
type: "onabort",
|
|
1788
|
+
error: new TypeError("request canceled"),
|
|
1789
|
+
response: null,
|
|
1790
|
+
}) == null) {
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1786
1793
|
resolve({
|
|
1787
1794
|
status: false,
|
|
1788
1795
|
data: [...argumentsList],
|
|
@@ -1807,6 +1814,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
1807
1814
|
if (response.length) {
|
|
1808
1815
|
response = response[0];
|
|
1809
1816
|
}
|
|
1817
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1818
|
+
type: "onerror",
|
|
1819
|
+
error: new TypeError("request error"),
|
|
1820
|
+
response: response,
|
|
1821
|
+
}) == null) {
|
|
1822
|
+
return;
|
|
1823
|
+
}
|
|
1810
1824
|
resolve({
|
|
1811
1825
|
status: false,
|
|
1812
1826
|
data: response,
|
|
@@ -1828,6 +1842,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
1828
1842
|
else if ("ontimeout" in this.context.#defaultDetails) {
|
|
1829
1843
|
this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
|
|
1830
1844
|
}
|
|
1845
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1846
|
+
type: "ontimeout",
|
|
1847
|
+
error: new TypeError("request timeout"),
|
|
1848
|
+
response: (argumentsList || [null])[0],
|
|
1849
|
+
}) == null) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1831
1852
|
resolve({
|
|
1832
1853
|
status: false,
|
|
1833
1854
|
data: [...argumentsList],
|
|
@@ -1908,6 +1929,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
1908
1929
|
}
|
|
1909
1930
|
/* 状态码2xx都是成功的 */
|
|
1910
1931
|
if (Math.floor(Response.status / 100) === 2) {
|
|
1932
|
+
if (this.context.HttpxResponseHook.successResponseCallBack(Response) ==
|
|
1933
|
+
null) {
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1911
1936
|
resolve({
|
|
1912
1937
|
status: true,
|
|
1913
1938
|
data: Response,
|
|
@@ -2156,14 +2181,24 @@ System.register('Utils', [], (function (exports) {
|
|
|
2156
2181
|
* @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
|
|
2157
2182
|
*/
|
|
2158
2183
|
use(fn) {
|
|
2159
|
-
|
|
2184
|
+
if (typeof fn !== "function") {
|
|
2185
|
+
console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
return this.context.HttpxRequestHook.add(fn);
|
|
2160
2189
|
},
|
|
2161
2190
|
/**
|
|
2162
2191
|
* 移除拦截器
|
|
2163
2192
|
* @param id 通过use返回的id
|
|
2164
2193
|
*/
|
|
2165
2194
|
eject(id) {
|
|
2166
|
-
return this.context.HttpxRequestHook.
|
|
2195
|
+
return this.context.HttpxRequestHook.delete(id);
|
|
2196
|
+
},
|
|
2197
|
+
/**
|
|
2198
|
+
* 移除所有拦截器
|
|
2199
|
+
*/
|
|
2200
|
+
ejectAll() {
|
|
2201
|
+
this.context.HttpxRequestHook.clearAll();
|
|
2167
2202
|
},
|
|
2168
2203
|
},
|
|
2169
2204
|
/**
|
|
@@ -2180,17 +2215,23 @@ System.register('Utils', [], (function (exports) {
|
|
|
2180
2215
|
*/
|
|
2181
2216
|
use(successFn, errorFn) {
|
|
2182
2217
|
if (typeof successFn !== "function" && typeof errorFn !== "function") {
|
|
2183
|
-
console.warn("[Httpx]
|
|
2218
|
+
console.warn("[Httpx-interceptors-response] 必须传入一个拦截器函数");
|
|
2184
2219
|
return;
|
|
2185
2220
|
}
|
|
2186
|
-
return this.context.HttpxResponseHook.
|
|
2221
|
+
return this.context.HttpxResponseHook.add(successFn, errorFn);
|
|
2187
2222
|
},
|
|
2188
2223
|
/**
|
|
2189
2224
|
* 移除拦截器
|
|
2190
2225
|
* @param id 通过use返回的id
|
|
2191
2226
|
*/
|
|
2192
2227
|
eject(id) {
|
|
2193
|
-
return this.context.HttpxResponseHook.
|
|
2228
|
+
return this.context.HttpxResponseHook.delete(id);
|
|
2229
|
+
},
|
|
2230
|
+
/**
|
|
2231
|
+
* 移除所有拦截器
|
|
2232
|
+
*/
|
|
2233
|
+
ejectAll() {
|
|
2234
|
+
this.context.HttpxResponseHook.clearAll();
|
|
2194
2235
|
},
|
|
2195
2236
|
},
|
|
2196
2237
|
};
|