@base-web-kits/base-tools-web 1.3.8 → 1.3.10

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.cjs CHANGED
@@ -1386,7 +1386,7 @@ function request(config) {
1386
1386
  onTaskReady == null ? void 0 : onTaskReady(task);
1387
1387
  return new Promise((resolve, reject) => {
1388
1388
  const execute = () => __async(null, null, function* () {
1389
- var _a, _b, _c, _d, _e, _f, _g, _h;
1389
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1390
1390
  const isGet = method === "GET";
1391
1391
  const isObjectData = isPlainObject(data);
1392
1392
  const isArrayData = !isObjectData && Array.isArray(data);
@@ -1440,7 +1440,7 @@ function request(config) {
1440
1440
  controller.abort();
1441
1441
  }, timeout);
1442
1442
  try {
1443
- const response = yield fetch(fillUrl, {
1443
+ let response = yield fetch(fillUrl, {
1444
1444
  method,
1445
1445
  headers: fillHeader,
1446
1446
  body: fillBody,
@@ -1448,9 +1448,20 @@ function request(config) {
1448
1448
  });
1449
1449
  if (!response.ok) {
1450
1450
  if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
1451
- throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
1451
+ let errorText;
1452
+ try {
1453
+ errorText = yield response.text();
1454
+ JSON.parse(errorText);
1455
+ } catch (e) {
1456
+ throw new Error(`HTTP Error ${response.status}`);
1457
+ }
1458
+ response = new Response(errorText, {
1459
+ status: response.status,
1460
+ statusText: response.statusText,
1461
+ headers: response.headers
1462
+ });
1452
1463
  }
1453
- if (enableChunked) {
1464
+ if (enableChunked && response.ok) {
1454
1465
  if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
1455
1466
  const res2 = yield handleStreamResponse(response, sseTask);
1456
1467
  logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
@@ -1477,17 +1488,18 @@ function request(config) {
1477
1488
  reject(res);
1478
1489
  }
1479
1490
  } catch (e) {
1491
+ if (showLoading) (_g = appConfig2.hideLoading) == null ? void 0 : _g.call(appConfig2);
1480
1492
  const status = "fail";
1481
1493
  const isAbortError = e instanceof DOMException && e.name === "AbortError";
1482
1494
  if (isAbortError && isTimeout) {
1483
- if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1495
+ if (toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1484
1496
  const timeoutError = new Error("Request Timeout");
1485
1497
  logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
1486
1498
  reject(timeoutError);
1487
1499
  return;
1488
1500
  }
1489
1501
  if (!isAbortError && toastError)
1490
- (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
1502
+ (_i = appConfig2.toast) == null ? void 0 : _i.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
1491
1503
  logRequestInfo({ status, config: logConfig, startTime, e });
1492
1504
  reject(e);
1493
1505
  } finally {