@whitesev/utils 1.5.4 → 1.5.5
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 +11 -8
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +11 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +11 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +11 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +11 -8
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +11 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +1 -1
- package/dist/src/Utils.d.ts +2 -3
- package/package.json +1 -1
- package/src/Httpx.ts +18 -8
package/dist/src/Httpx.d.ts
CHANGED
|
@@ -1162,7 +1162,7 @@ declare class Httpx {
|
|
|
1162
1162
|
* @param errorFn 设置的响应后回调函数,如果返回响应,则使用返回的响应,如果返回null|undefined,则阻止响应
|
|
1163
1163
|
* + 超出 2xx 范围的状态码都会触发该函数
|
|
1164
1164
|
*/
|
|
1165
|
-
use(successFn?:
|
|
1165
|
+
use(successFn?: <T extends HttpxAsyncResultData>(response: HttpxAsyncResultData) => void | T, errorFn?: <T extends HttpxHookErrorData>(data: T) => void | T): string | undefined;
|
|
1166
1166
|
/**
|
|
1167
1167
|
* 移除拦截器
|
|
1168
1168
|
* @param id 通过use返回的id
|
package/dist/src/Utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference path="../../src/ajaxHooker/index.d.ts" />
|
|
2
1
|
import { ColorConversion } from "./ColorConversion";
|
|
3
2
|
import { GBKEncoder } from "./GBKEncoder";
|
|
4
3
|
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
@@ -1413,8 +1412,8 @@ declare class Utils {
|
|
|
1413
1412
|
*/
|
|
1414
1413
|
tryCatch: (...args: any) => {
|
|
1415
1414
|
config(paramDetails: import("./TryCatch").UtilsTryCatchConfig): any;
|
|
1416
|
-
error(handler:
|
|
1417
|
-
run<A extends any[], R>(callback:
|
|
1415
|
+
error(handler: ((...args: any[]) => any) | string | Function): any;
|
|
1416
|
+
run<A extends any[], R>(callback: ((...args: A) => R) | string | Function, __context__?: any): import("./TryCatch").UtilsTryCatchType;
|
|
1418
1417
|
};
|
|
1419
1418
|
/**
|
|
1420
1419
|
* 数组去重,去除重复的值
|
package/package.json
CHANGED
package/src/Httpx.ts
CHANGED
|
@@ -1305,13 +1305,17 @@ class Httpx {
|
|
|
1305
1305
|
},
|
|
1306
1306
|
/**
|
|
1307
1307
|
* 成功的回调
|
|
1308
|
-
* @param response
|
|
1308
|
+
* @param response 响应
|
|
1309
|
+
* @param details 请求的配置
|
|
1309
1310
|
*/
|
|
1310
|
-
successResponseCallBack(
|
|
1311
|
+
successResponseCallBack(
|
|
1312
|
+
response: HttpxAsyncResultData,
|
|
1313
|
+
details: HttpxDetails
|
|
1314
|
+
) {
|
|
1311
1315
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1312
1316
|
let item = this.$config.configList[index];
|
|
1313
1317
|
if (typeof item.successFn === "function") {
|
|
1314
|
-
if (item.successFn(response) == null) {
|
|
1318
|
+
if (item.successFn(response, details) == null) {
|
|
1315
1319
|
return;
|
|
1316
1320
|
}
|
|
1317
1321
|
}
|
|
@@ -1320,12 +1324,13 @@ class Httpx {
|
|
|
1320
1324
|
},
|
|
1321
1325
|
/**
|
|
1322
1326
|
* 失败的回调
|
|
1323
|
-
* @param
|
|
1327
|
+
* @param data 配置
|
|
1324
1328
|
*/
|
|
1325
1329
|
errorResponseCallBack(data: {
|
|
1326
1330
|
type: "onerror" | "ontimeout" | "onabort";
|
|
1327
1331
|
error: Error;
|
|
1328
1332
|
response: any;
|
|
1333
|
+
details: HttpxDetails;
|
|
1329
1334
|
}) {
|
|
1330
1335
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1331
1336
|
let item = this.$config.configList[index];
|
|
@@ -1632,6 +1637,7 @@ class Httpx {
|
|
|
1632
1637
|
type: "onabort",
|
|
1633
1638
|
error: new TypeError("request canceled"),
|
|
1634
1639
|
response: null,
|
|
1640
|
+
details: details,
|
|
1635
1641
|
}) == null
|
|
1636
1642
|
) {
|
|
1637
1643
|
return;
|
|
@@ -1669,6 +1675,7 @@ class Httpx {
|
|
|
1669
1675
|
type: "onerror",
|
|
1670
1676
|
error: new TypeError("request error"),
|
|
1671
1677
|
response: response,
|
|
1678
|
+
details: details,
|
|
1672
1679
|
}) == null
|
|
1673
1680
|
) {
|
|
1674
1681
|
return;
|
|
@@ -1703,6 +1710,7 @@ class Httpx {
|
|
|
1703
1710
|
type: "ontimeout",
|
|
1704
1711
|
error: new TypeError("request timeout"),
|
|
1705
1712
|
response: (argumentsList || [null])[0],
|
|
1713
|
+
details: details,
|
|
1706
1714
|
}) == null
|
|
1707
1715
|
) {
|
|
1708
1716
|
return;
|
|
@@ -1797,8 +1805,10 @@ class Httpx {
|
|
|
1797
1805
|
/* 状态码2xx都是成功的 */
|
|
1798
1806
|
if (Math.floor(Response.status / 100) === 2) {
|
|
1799
1807
|
if (
|
|
1800
|
-
this.context.HttpxResponseHook.successResponseCallBack(
|
|
1801
|
-
|
|
1808
|
+
this.context.HttpxResponseHook.successResponseCallBack(
|
|
1809
|
+
Response,
|
|
1810
|
+
details
|
|
1811
|
+
) == null
|
|
1802
1812
|
) {
|
|
1803
1813
|
return;
|
|
1804
1814
|
}
|
|
@@ -1933,7 +1943,7 @@ class Httpx {
|
|
|
1933
1943
|
/** 响应xml文档 */
|
|
1934
1944
|
let responseXML = "";
|
|
1935
1945
|
|
|
1936
|
-
let arrayBuffer = await resp.arrayBuffer;
|
|
1946
|
+
let arrayBuffer = await resp.arrayBuffer();
|
|
1937
1947
|
|
|
1938
1948
|
let encoding = "utf-8";
|
|
1939
1949
|
if (resp.headers.has("Content-Type")) {
|
|
@@ -1945,7 +1955,7 @@ class Httpx {
|
|
|
1945
1955
|
}
|
|
1946
1956
|
}
|
|
1947
1957
|
let textDecoder = new TextDecoder(encoding);
|
|
1948
|
-
responseText = textDecoder.decode(
|
|
1958
|
+
responseText = textDecoder.decode(arrayBuffer);
|
|
1949
1959
|
response = responseText;
|
|
1950
1960
|
|
|
1951
1961
|
if (details.responseType === "arraybuffer") {
|