@whitesev/utils 1.8.0 → 1.9.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 +78 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +78 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +78 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +78 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +78 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +78 -40
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1563,14 +1563,23 @@ class Httpx {
|
|
|
1563
1563
|
* @private
|
|
1564
1564
|
*/
|
|
1565
1565
|
beforeRequestCallBack(details) {
|
|
1566
|
-
if (details.allowInterceptConfig) {
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
!details.allowInterceptConfig.beforeRequest) {
|
|
1570
|
-
// 设置了禁止拦截
|
|
1566
|
+
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1567
|
+
if (!details.allowInterceptConfig) {
|
|
1568
|
+
// 不允许拦截
|
|
1571
1569
|
return details;
|
|
1572
1570
|
}
|
|
1573
1571
|
}
|
|
1572
|
+
else {
|
|
1573
|
+
if (details.allowInterceptConfig != null) {
|
|
1574
|
+
// 配置存在
|
|
1575
|
+
// 细分处理是否拦截
|
|
1576
|
+
if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
|
|
1577
|
+
!details.allowInterceptConfig.beforeRequest) {
|
|
1578
|
+
// 设置了禁止拦截
|
|
1579
|
+
return details;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1574
1583
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1575
1584
|
let item = this.$config.configList[index];
|
|
1576
1585
|
if (typeof item.fn === "function") {
|
|
@@ -1632,15 +1641,24 @@ class Httpx {
|
|
|
1632
1641
|
* @param details 请求的配置
|
|
1633
1642
|
*/
|
|
1634
1643
|
successResponseCallBack(response, details) {
|
|
1635
|
-
if (details.allowInterceptConfig) {
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
"boolean" &&
|
|
1639
|
-
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1640
|
-
// 设置了禁止拦截
|
|
1644
|
+
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1645
|
+
if (!details.allowInterceptConfig) {
|
|
1646
|
+
// 不允许拦截
|
|
1641
1647
|
return details;
|
|
1642
1648
|
}
|
|
1643
1649
|
}
|
|
1650
|
+
else {
|
|
1651
|
+
if (details.allowInterceptConfig != null) {
|
|
1652
|
+
// 配置存在
|
|
1653
|
+
// 细分处理是否拦截
|
|
1654
|
+
if (typeof details.allowInterceptConfig.afterResponseSuccess ===
|
|
1655
|
+
"boolean" &&
|
|
1656
|
+
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1657
|
+
// 设置了禁止拦截
|
|
1658
|
+
return details;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1644
1662
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1645
1663
|
let item = this.$config.configList[index];
|
|
1646
1664
|
if (typeof item.successFn === "function") {
|
|
@@ -1654,17 +1672,28 @@ class Httpx {
|
|
|
1654
1672
|
/**
|
|
1655
1673
|
* 失败的回调
|
|
1656
1674
|
* @param data 配置
|
|
1675
|
+
* @returns
|
|
1676
|
+
* 返回null|undefined就是拦截掉了
|
|
1657
1677
|
*/
|
|
1658
1678
|
errorResponseCallBack(data) {
|
|
1659
|
-
if (data.details.allowInterceptConfig) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
"boolean" &&
|
|
1663
|
-
!data.details.allowInterceptConfig.afterResponseError) {
|
|
1664
|
-
// 设置了禁止拦截
|
|
1679
|
+
if (typeof data.details.allowInterceptConfig === "boolean") {
|
|
1680
|
+
if (!data.details.allowInterceptConfig) {
|
|
1681
|
+
// 不允许拦截
|
|
1665
1682
|
return data;
|
|
1666
1683
|
}
|
|
1667
1684
|
}
|
|
1685
|
+
else {
|
|
1686
|
+
if (data.details.allowInterceptConfig != null) {
|
|
1687
|
+
// 配置存在
|
|
1688
|
+
// 细分处理是否拦截
|
|
1689
|
+
if (typeof data.details.allowInterceptConfig.afterResponseError ===
|
|
1690
|
+
"boolean" &&
|
|
1691
|
+
!data.details.allowInterceptConfig.afterResponseError) {
|
|
1692
|
+
// 设置了禁止拦截
|
|
1693
|
+
return data;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1668
1697
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1669
1698
|
let item = this.$config.configList[index];
|
|
1670
1699
|
if (typeof item.errorFn === "function") {
|
|
@@ -1735,10 +1764,11 @@ class Httpx {
|
|
|
1735
1764
|
/**
|
|
1736
1765
|
* 获取请求配置
|
|
1737
1766
|
* @param method 当前请求方法,默认get
|
|
1738
|
-
* @param resolve promise回调
|
|
1739
1767
|
* @param details 请求配置
|
|
1768
|
+
* @param resolve promise回调
|
|
1769
|
+
* @param reject 抛出错误回调
|
|
1740
1770
|
*/
|
|
1741
|
-
getDetails(method, resolve,
|
|
1771
|
+
getDetails(method, details, resolve, reject) {
|
|
1742
1772
|
let that = this;
|
|
1743
1773
|
let result = {
|
|
1744
1774
|
url: details.url || this.context.#defaultDetails.url,
|
|
@@ -1764,10 +1794,10 @@ class Httpx {
|
|
|
1764
1794
|
user: details.user || this.context.#defaultDetails.user,
|
|
1765
1795
|
password: details.password || this.context.#defaultDetails.password,
|
|
1766
1796
|
onabort(...args) {
|
|
1767
|
-
that.context.HttpxCallBack.onAbort(details, resolve, args);
|
|
1797
|
+
that.context.HttpxCallBack.onAbort(details, resolve, reject, args);
|
|
1768
1798
|
},
|
|
1769
1799
|
onerror(...args) {
|
|
1770
|
-
that.context.HttpxCallBack.onError(details, resolve, args);
|
|
1800
|
+
that.context.HttpxCallBack.onError(details, resolve, reject, args);
|
|
1771
1801
|
},
|
|
1772
1802
|
onloadstart(...args) {
|
|
1773
1803
|
that.context.HttpxCallBack.onLoadStart(details, args);
|
|
@@ -1779,10 +1809,10 @@ class Httpx {
|
|
|
1779
1809
|
that.context.HttpxCallBack.onReadyStateChange(details, args);
|
|
1780
1810
|
},
|
|
1781
1811
|
ontimeout(...args) {
|
|
1782
|
-
that.context.HttpxCallBack.onTimeout(details, resolve, args);
|
|
1812
|
+
that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
|
|
1783
1813
|
},
|
|
1784
1814
|
onload(...args) {
|
|
1785
|
-
that.context.HttpxCallBack.onLoad(details, resolve, args);
|
|
1815
|
+
that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
|
|
1786
1816
|
},
|
|
1787
1817
|
};
|
|
1788
1818
|
if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
|
|
@@ -1912,9 +1942,10 @@ class Httpx {
|
|
|
1912
1942
|
* onabort请求被取消-触发
|
|
1913
1943
|
* @param details 配置
|
|
1914
1944
|
* @param resolve 回调
|
|
1945
|
+
* @param reject 抛出错误
|
|
1915
1946
|
* @param argumentsList 参数列表
|
|
1916
1947
|
*/
|
|
1917
|
-
onAbort(details, resolve, argumentsList) {
|
|
1948
|
+
onAbort(details, resolve, reject, argumentsList) {
|
|
1918
1949
|
if ("onabort" in details) {
|
|
1919
1950
|
details.onabort.apply(this, argumentsList);
|
|
1920
1951
|
}
|
|
@@ -1927,6 +1958,7 @@ class Httpx {
|
|
|
1927
1958
|
response: null,
|
|
1928
1959
|
details: details,
|
|
1929
1960
|
}) == null) {
|
|
1961
|
+
// reject(new TypeError("response is intercept with onabort"));
|
|
1930
1962
|
return;
|
|
1931
1963
|
}
|
|
1932
1964
|
resolve({
|
|
@@ -1940,9 +1972,10 @@ class Httpx {
|
|
|
1940
1972
|
* onerror请求异常-触发
|
|
1941
1973
|
* @param details 配置
|
|
1942
1974
|
* @param resolve 回调
|
|
1975
|
+
* @param reject 抛出错误
|
|
1943
1976
|
* @param argumentsList 响应的参数列表
|
|
1944
1977
|
*/
|
|
1945
|
-
onError(details, resolve, argumentsList) {
|
|
1978
|
+
onError(details, resolve, reject, argumentsList) {
|
|
1946
1979
|
if ("onerror" in details) {
|
|
1947
1980
|
details.onerror.apply(this, argumentsList);
|
|
1948
1981
|
}
|
|
@@ -1959,6 +1992,7 @@ class Httpx {
|
|
|
1959
1992
|
response: response,
|
|
1960
1993
|
details: details,
|
|
1961
1994
|
}) == null) {
|
|
1995
|
+
// reject(new TypeError("response is intercept with onerror"));
|
|
1962
1996
|
return;
|
|
1963
1997
|
}
|
|
1964
1998
|
resolve({
|
|
@@ -1973,9 +2007,10 @@ class Httpx {
|
|
|
1973
2007
|
* ontimeout请求超时-触发
|
|
1974
2008
|
* @param details 配置
|
|
1975
2009
|
* @param resolve 回调
|
|
2010
|
+
* @param reject 抛出错误
|
|
1976
2011
|
* @param argumentsList 参数列表
|
|
1977
2012
|
*/
|
|
1978
|
-
onTimeout(details, resolve, argumentsList) {
|
|
2013
|
+
onTimeout(details, resolve, reject, argumentsList) {
|
|
1979
2014
|
if ("ontimeout" in details) {
|
|
1980
2015
|
details.ontimeout.apply(this, argumentsList);
|
|
1981
2016
|
}
|
|
@@ -1988,6 +2023,7 @@ class Httpx {
|
|
|
1988
2023
|
response: (argumentsList || [null])[0],
|
|
1989
2024
|
details: details,
|
|
1990
2025
|
}) == null) {
|
|
2026
|
+
// reject(new TypeError("response is intercept with ontimeout"));
|
|
1991
2027
|
return;
|
|
1992
2028
|
}
|
|
1993
2029
|
resolve({
|
|
@@ -2014,9 +2050,10 @@ class Httpx {
|
|
|
2014
2050
|
* onload加载完毕-触发
|
|
2015
2051
|
* @param details 请求的配置
|
|
2016
2052
|
* @param resolve 回调
|
|
2053
|
+
* @param reject 抛出错误
|
|
2017
2054
|
* @param argumentsList 参数列表
|
|
2018
2055
|
*/
|
|
2019
|
-
onLoad(details, resolve, argumentsList) {
|
|
2056
|
+
onLoad(details, resolve, reject, argumentsList) {
|
|
2020
2057
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2021
2058
|
let Response = argumentsList[0];
|
|
2022
2059
|
/* responseText为空,response不为空的情况 */
|
|
@@ -2071,6 +2108,7 @@ class Httpx {
|
|
|
2071
2108
|
/* 状态码2xx都是成功的 */
|
|
2072
2109
|
if (Math.floor(Response.status / 100) === 2) {
|
|
2073
2110
|
if (this.context.HttpxResponseHook.successResponseCallBack(Response, details) == null) {
|
|
2111
|
+
// reject(new TypeError("response is intercept with onloada"));
|
|
2074
2112
|
return;
|
|
2075
2113
|
}
|
|
2076
2114
|
resolve({
|
|
@@ -2082,7 +2120,7 @@ class Httpx {
|
|
|
2082
2120
|
});
|
|
2083
2121
|
}
|
|
2084
2122
|
else {
|
|
2085
|
-
this.context.HttpxCallBack.onError(details, resolve, argumentsList);
|
|
2123
|
+
this.context.HttpxCallBack.onError(details, resolve, reject, argumentsList);
|
|
2086
2124
|
}
|
|
2087
2125
|
},
|
|
2088
2126
|
/**
|
|
@@ -2393,8 +2431,8 @@ class Httpx {
|
|
|
2393
2431
|
async get(...args) {
|
|
2394
2432
|
let that = this;
|
|
2395
2433
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2396
|
-
return new Promise((resolve) => {
|
|
2397
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2434
|
+
return new Promise((resolve, reject) => {
|
|
2435
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
|
|
2398
2436
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2399
2437
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2400
2438
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2406,8 +2444,8 @@ class Httpx {
|
|
|
2406
2444
|
async post(...args) {
|
|
2407
2445
|
let that = this;
|
|
2408
2446
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2409
|
-
return new Promise((resolve) => {
|
|
2410
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2447
|
+
return new Promise((resolve, reject) => {
|
|
2448
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
|
|
2411
2449
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2412
2450
|
that.HttpxRequest.request(requestDetails);
|
|
2413
2451
|
});
|
|
@@ -2418,8 +2456,8 @@ class Httpx {
|
|
|
2418
2456
|
async head(...args) {
|
|
2419
2457
|
let that = this;
|
|
2420
2458
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2421
|
-
return new Promise((resolve) => {
|
|
2422
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2459
|
+
return new Promise((resolve, reject) => {
|
|
2460
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
|
|
2423
2461
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2424
2462
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2425
2463
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2431,8 +2469,8 @@ class Httpx {
|
|
|
2431
2469
|
async options(...args) {
|
|
2432
2470
|
let that = this;
|
|
2433
2471
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2434
|
-
return new Promise((resolve) => {
|
|
2435
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2472
|
+
return new Promise((resolve, reject) => {
|
|
2473
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
|
|
2436
2474
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2437
2475
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2438
2476
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2444,8 +2482,8 @@ class Httpx {
|
|
|
2444
2482
|
async delete(...args) {
|
|
2445
2483
|
let that = this;
|
|
2446
2484
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2447
|
-
return new Promise((resolve) => {
|
|
2448
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2485
|
+
return new Promise((resolve, reject) => {
|
|
2486
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
|
|
2449
2487
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2450
2488
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2451
2489
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2457,8 +2495,8 @@ class Httpx {
|
|
|
2457
2495
|
async put(...args) {
|
|
2458
2496
|
let that = this;
|
|
2459
2497
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2460
|
-
return new Promise((resolve) => {
|
|
2461
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2498
|
+
return new Promise((resolve, reject) => {
|
|
2499
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
|
|
2462
2500
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2463
2501
|
that.HttpxRequest.request(requestDetails);
|
|
2464
2502
|
});
|