@base-web-kits/base-tools-web 1.3.16 → 1.3.20
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/base-tools-web.umd.global.js +10 -2
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/web/network/request.ts +14 -2
package/package.json
CHANGED
|
@@ -431,7 +431,7 @@ export function request<T, D extends RequestData = RequestData>(config: RequestC
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
if (!isAbortError && toastError)
|
|
434
|
-
appConfig.toast?.({ status, msg: `请求失败,${
|
|
434
|
+
appConfig.toast?.({ status, msg: `请求失败,${JSON.stringify(e)}` });
|
|
435
435
|
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
436
436
|
reject(e);
|
|
437
437
|
} finally {
|
|
@@ -506,7 +506,7 @@ function logRequestInfo(options: {
|
|
|
506
506
|
info.res = cloneDeep(res); // 深拷贝,避免外部修改对象,造成输出不一致
|
|
507
507
|
log('info', info);
|
|
508
508
|
} else {
|
|
509
|
-
info.e = e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } :
|
|
509
|
+
info.e = e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } : e; // Error需转为普通对象,否则发送网络日志会序列化成空对象
|
|
510
510
|
log('error', info);
|
|
511
511
|
}
|
|
512
512
|
}
|
|
@@ -565,6 +565,18 @@ async function handleStreamResponse(response: Response, sseTask: SseTask) {
|
|
|
565
565
|
* 解析响应数据
|
|
566
566
|
*/
|
|
567
567
|
async function parseResponse(response: Response, responseType: string) {
|
|
568
|
+
if (!response.ok) {
|
|
569
|
+
// HTTP 非 2xx && responseType是'arraybuffer'或'text' (如服务端设置401+JSON体,确保toLogin能正常触发)
|
|
570
|
+
const text = await response.text();
|
|
571
|
+
|
|
572
|
+
try {
|
|
573
|
+
return JSON.parse(text);
|
|
574
|
+
} catch {
|
|
575
|
+
throw new Error(`HTTP Error ${response.status}: ${text || response.statusText}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// HTTP 为 2xx 的响应数据
|
|
568
580
|
let resData: ResponseData;
|
|
569
581
|
if (responseType === 'arraybuffer') {
|
|
570
582
|
resData = await response.arrayBuffer();
|