@whitesev/utils 1.4.9 → 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 +8 -1
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +8 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +8 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +8 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +8 -1
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +8 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +2 -2
- package/package.json +1 -1
- package/src/Httpx.ts +18 -9
package/dist/src/Httpx.d.ts
CHANGED
|
@@ -1157,8 +1157,8 @@ declare class Httpx {
|
|
|
1157
1157
|
* @param errorFn 设置的响应后回调函数,如果返回响应,则使用返回的响应,如果返回null|undefined,则阻止响应
|
|
1158
1158
|
* + 超出 2xx 范围的状态码都会触发该函数
|
|
1159
1159
|
*/
|
|
1160
|
-
use(successFn
|
|
1161
|
-
type: "onerror" | "ontimeout";
|
|
1160
|
+
use(successFn?: (response: HttpxAsyncResultData) => void, errorFn?: (data: {
|
|
1161
|
+
type: "onerror" | "ontimeout" | "onabort";
|
|
1162
1162
|
error: Error;
|
|
1163
1163
|
response: any;
|
|
1164
1164
|
}) => void): string | undefined;
|
package/package.json
CHANGED
package/src/Httpx.ts
CHANGED
|
@@ -1292,8 +1292,8 @@ class Httpx {
|
|
|
1292
1292
|
configList: <
|
|
1293
1293
|
{
|
|
1294
1294
|
id: string;
|
|
1295
|
-
successFn
|
|
1296
|
-
errorFn
|
|
1295
|
+
successFn?: Function;
|
|
1296
|
+
errorFn?: Function;
|
|
1297
1297
|
}[]
|
|
1298
1298
|
>[],
|
|
1299
1299
|
},
|
|
@@ -1317,7 +1317,7 @@ class Httpx {
|
|
|
1317
1317
|
* @param response
|
|
1318
1318
|
*/
|
|
1319
1319
|
errorResponseCallBack(data: {
|
|
1320
|
-
type: "onerror" | "ontimeout";
|
|
1320
|
+
type: "onerror" | "ontimeout" | "onabort";
|
|
1321
1321
|
error: Error;
|
|
1322
1322
|
response: any;
|
|
1323
1323
|
}) {
|
|
@@ -1334,7 +1334,7 @@ class Httpx {
|
|
|
1334
1334
|
/**
|
|
1335
1335
|
* 添加请求前的回调处理配置
|
|
1336
1336
|
*/
|
|
1337
|
-
add(successFn
|
|
1337
|
+
add(successFn?: Function, errorFn?: Function) {
|
|
1338
1338
|
let id = GenerateUUID();
|
|
1339
1339
|
this.$config.configList.push({
|
|
1340
1340
|
id: id,
|
|
@@ -1621,6 +1621,15 @@ class Httpx {
|
|
|
1621
1621
|
} else if ("onabort" in this.context.#defaultDetails) {
|
|
1622
1622
|
this.context.#defaultDetails!.onabort!.apply(this, argumentsList);
|
|
1623
1623
|
}
|
|
1624
|
+
if (
|
|
1625
|
+
this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1626
|
+
type: "onabort",
|
|
1627
|
+
error: new TypeError("request canceled"),
|
|
1628
|
+
response: null,
|
|
1629
|
+
}) == null
|
|
1630
|
+
) {
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1624
1633
|
resolve({
|
|
1625
1634
|
status: false,
|
|
1626
1635
|
data: [...argumentsList],
|
|
@@ -2101,18 +2110,18 @@ class Httpx {
|
|
|
2101
2110
|
* + 超出 2xx 范围的状态码都会触发该函数
|
|
2102
2111
|
*/
|
|
2103
2112
|
use(
|
|
2104
|
-
successFn
|
|
2105
|
-
errorFn
|
|
2106
|
-
type: "onerror" | "ontimeout";
|
|
2113
|
+
successFn?: (response: HttpxAsyncResultData) => void,
|
|
2114
|
+
errorFn?: (data: {
|
|
2115
|
+
type: "onerror" | "ontimeout" | "onabort";
|
|
2107
2116
|
error: Error;
|
|
2108
2117
|
response: any;
|
|
2109
2118
|
}) => void
|
|
2110
2119
|
) {
|
|
2111
2120
|
if (typeof successFn !== "function" && typeof errorFn !== "function") {
|
|
2112
|
-
console.warn("[Httpx-interceptors-response]
|
|
2121
|
+
console.warn("[Httpx-interceptors-response] 必须传入一个拦截器函数");
|
|
2113
2122
|
return;
|
|
2114
2123
|
}
|
|
2115
|
-
return this.context.HttpxResponseHook.add(successFn
|
|
2124
|
+
return this.context.HttpxResponseHook.add(successFn!, errorFn!);
|
|
2116
2125
|
},
|
|
2117
2126
|
/**
|
|
2118
2127
|
* 移除拦截器
|