@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.mjs CHANGED
@@ -1303,7 +1303,7 @@ function request(config) {
1303
1303
  onTaskReady == null ? void 0 : onTaskReady(task);
1304
1304
  return new Promise((resolve, reject) => {
1305
1305
  const execute = () => __async(null, null, function* () {
1306
- var _a, _b, _c, _d, _e, _f, _g, _h;
1306
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1307
1307
  const isGet = method === "GET";
1308
1308
  const isObjectData = isPlainObject(data);
1309
1309
  const isArrayData = !isObjectData && Array.isArray(data);
@@ -1357,7 +1357,7 @@ function request(config) {
1357
1357
  controller.abort();
1358
1358
  }, timeout);
1359
1359
  try {
1360
- const response = yield fetch(fillUrl, {
1360
+ let response = yield fetch(fillUrl, {
1361
1361
  method,
1362
1362
  headers: fillHeader,
1363
1363
  body: fillBody,
@@ -1365,9 +1365,20 @@ function request(config) {
1365
1365
  });
1366
1366
  if (!response.ok) {
1367
1367
  if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
1368
- throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
1368
+ let errorText;
1369
+ try {
1370
+ errorText = yield response.text();
1371
+ JSON.parse(errorText);
1372
+ } catch (e) {
1373
+ throw new Error(`HTTP Error ${response.status}`);
1374
+ }
1375
+ response = new Response(errorText, {
1376
+ status: response.status,
1377
+ statusText: response.statusText,
1378
+ headers: response.headers
1379
+ });
1369
1380
  }
1370
- if (enableChunked) {
1381
+ if (enableChunked && response.ok) {
1371
1382
  if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
1372
1383
  const res2 = yield handleStreamResponse(response, sseTask);
1373
1384
  logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
@@ -1394,17 +1405,18 @@ function request(config) {
1394
1405
  reject(res);
1395
1406
  }
1396
1407
  } catch (e) {
1408
+ if (showLoading) (_g = appConfig2.hideLoading) == null ? void 0 : _g.call(appConfig2);
1397
1409
  const status = "fail";
1398
1410
  const isAbortError = e instanceof DOMException && e.name === "AbortError";
1399
1411
  if (isAbortError && isTimeout) {
1400
- if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1412
+ if (toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1401
1413
  const timeoutError = new Error("Request Timeout");
1402
1414
  logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
1403
1415
  reject(timeoutError);
1404
1416
  return;
1405
1417
  }
1406
1418
  if (!isAbortError && toastError)
1407
- (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
1419
+ (_i = appConfig2.toast) == null ? void 0 : _i.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
1408
1420
  logRequestInfo({ status, config: logConfig, startTime, e });
1409
1421
  reject(e);
1410
1422
  } finally {