@aliyun-obv/api 4.5.3 → 4.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/api.d.ts CHANGED
@@ -119,7 +119,7 @@ declare const sseClient: (api: string, params: Record<string, any>, options: Iss
119
119
  * @param response easyfeatch 返回体
120
120
  * @returns
121
121
  */
122
- declare function showAlertDialog(response: any, config?: ShowConfig, request?: any): boolean;
122
+ declare function showAlertDialog(response: any, config?: ShowConfig, request?: any, extra?: any): boolean;
123
123
  declare function showAlertDialogWhenNeedLogin(response: any, config?: {}): void;
124
124
 
125
125
  declare namespace metaService {
package/dist/api.es.js CHANGED
@@ -21,23 +21,23 @@ function getPostParam(obj = {}) {
21
21
  }).join("&");
22
22
  }
23
23
 
24
- var __defProp$5 = Object.defineProperty;
25
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
26
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
27
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
28
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
29
- var __spreadValues$5 = (a, b) => {
24
+ var __defProp$6 = Object.defineProperty;
25
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
26
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
27
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
28
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
29
+ var __spreadValues$6 = (a, b) => {
30
30
  for (var prop in b || (b = {}))
31
- if (__hasOwnProp$5.call(b, prop))
32
- __defNormalProp$5(a, prop, b[prop]);
33
- if (__getOwnPropSymbols$5)
34
- for (var prop of __getOwnPropSymbols$5(b)) {
35
- if (__propIsEnum$5.call(b, prop))
36
- __defNormalProp$5(a, prop, b[prop]);
31
+ if (__hasOwnProp$6.call(b, prop))
32
+ __defNormalProp$6(a, prop, b[prop]);
33
+ if (__getOwnPropSymbols$6)
34
+ for (var prop of __getOwnPropSymbols$6(b)) {
35
+ if (__propIsEnum$6.call(b, prop))
36
+ __defNormalProp$6(a, prop, b[prop]);
37
37
  }
38
38
  return a;
39
39
  };
40
- var __publicField$1 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
40
+ var __publicField$1 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
41
41
  var __async$a = (__this, __arguments, generator) => {
42
42
  return new Promise((resolve, reject) => {
43
43
  var fulfilled = (value) => {
@@ -113,7 +113,7 @@ class BaseFetch {
113
113
  } catch (e) {
114
114
  }
115
115
  if ((url.startsWith("http:") || url.startsWith("https:")) && !url.startsWith(window.location.host)) {
116
- newInit = __spreadValues$5({}, Object.assign({}, init, { credentials: "include" }));
116
+ newInit = __spreadValues$6({}, Object.assign({}, init, { credentials: "include" }));
117
117
  }
118
118
  if (this.defaults.beforeRequest) {
119
119
  return this.defaults.beforeRequest(url, params, newInit, options);
@@ -373,6 +373,18 @@ function convertErrorDetaisAuth(o) {
373
373
  function createNoXSS(htmlString) {
374
374
  return htmlString.substr(0, 400);
375
375
  }
376
+ function structuredErrorMessage(message) {
377
+ try {
378
+ const parsed = JSON.parse(message);
379
+ const isStructured = parsed && typeof parsed === "object" && parsed.result && parsed.level && Array.isArray(parsed.statusItem) && parsed.statusItem.length > 0 && parsed.statusItem.every((item) => item == null ? void 0 : item.code);
380
+ if (isStructured) {
381
+ return parsed.statusItem;
382
+ }
383
+ return false;
384
+ } catch (e) {
385
+ return false;
386
+ }
387
+ }
376
388
  const errorMsgHandler = (err) => {
377
389
  let msg = window.ALIYUN_SLS_CONSOLE_MESSAGE && window.ALIYUN_SLS_CONSOLE_MESSAGE[err.code];
378
390
  if (err.code === "OnlyInternalAccess") {
@@ -419,25 +431,25 @@ function addRUMLog(log) {
419
431
  }
420
432
  }
421
433
 
422
- var __defProp$4 = Object.defineProperty;
423
- var __defProps$4 = Object.defineProperties;
424
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
425
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
426
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
427
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
428
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
429
- var __spreadValues$4 = (a, b) => {
434
+ var __defProp$5 = Object.defineProperty;
435
+ var __defProps$5 = Object.defineProperties;
436
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
437
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
438
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
439
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
440
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
441
+ var __spreadValues$5 = (a, b) => {
430
442
  for (var prop in b || (b = {}))
431
- if (__hasOwnProp$4.call(b, prop))
432
- __defNormalProp$4(a, prop, b[prop]);
433
- if (__getOwnPropSymbols$4)
434
- for (var prop of __getOwnPropSymbols$4(b)) {
435
- if (__propIsEnum$4.call(b, prop))
436
- __defNormalProp$4(a, prop, b[prop]);
443
+ if (__hasOwnProp$5.call(b, prop))
444
+ __defNormalProp$5(a, prop, b[prop]);
445
+ if (__getOwnPropSymbols$5)
446
+ for (var prop of __getOwnPropSymbols$5(b)) {
447
+ if (__propIsEnum$5.call(b, prop))
448
+ __defNormalProp$5(a, prop, b[prop]);
437
449
  }
438
450
  return a;
439
451
  };
440
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
452
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
441
453
  var __async$9 = (__this, __arguments, generator) => {
442
454
  return new Promise((resolve, reject) => {
443
455
  var fulfilled = (value) => {
@@ -464,7 +476,7 @@ commonEasyFetch.defaults.postDefaultInit.headers["Accept"] = "application/json";
464
476
  commonEasyFetch.defaults.afterResponse = (response) => __async$9(void 0, null, function* () {
465
477
  if (response.status >= 200 && response.status < 300) {
466
478
  const data = yield response.json();
467
- return __spreadProps$4(__spreadValues$4({}, data != null ? data : {}), {
479
+ return __spreadProps$5(__spreadValues$5({}, data != null ? data : {}), {
468
480
  response
469
481
  });
470
482
  } else {
@@ -472,10 +484,29 @@ commonEasyFetch.defaults.afterResponse = (response) => __async$9(void 0, null, f
472
484
  }
473
485
  });
474
486
 
487
+ var __defProp$4 = Object.defineProperty;
488
+ var __defProps$4 = Object.defineProperties;
489
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
490
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
491
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
492
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
493
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
494
+ var __spreadValues$4 = (a, b) => {
495
+ for (var prop in b || (b = {}))
496
+ if (__hasOwnProp$4.call(b, prop))
497
+ __defNormalProp$4(a, prop, b[prop]);
498
+ if (__getOwnPropSymbols$4)
499
+ for (var prop of __getOwnPropSymbols$4(b)) {
500
+ if (__propIsEnum$4.call(b, prop))
501
+ __defNormalProp$4(a, prop, b[prop]);
502
+ }
503
+ return a;
504
+ };
505
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
475
506
  const ERROR_TITLE = i18n.ERROR;
476
507
  i18n.OK;
477
508
  let isGlobalAlertShow = false;
478
- function showConsoleBaseAlertDialog(response, config = {}, request) {
509
+ function showConsoleBaseAlertDialog(response, config = {}, request, extra = {}) {
479
510
  var _a, _b, _c;
480
511
  if ((response == null ? void 0 : response.code) === "200") {
481
512
  return false;
@@ -486,10 +517,10 @@ function showConsoleBaseAlertDialog(response, config = {}, request) {
486
517
  message: response.message,
487
518
  code: response.code,
488
519
  requestId: response.requestId,
489
- details: {
520
+ details: __spreadValues$4({
490
521
  url: request ? request.api : void 0,
491
522
  method: request ? request.method : void 0
492
- }
523
+ }, extra || {})
493
524
  };
494
525
  if (response.code === "Unauthorized") {
495
526
  if ((_a = response == null ? void 0 : response.rawResponseError) == null ? void 0 : _a.accessDeniedDetail) {
@@ -592,7 +623,7 @@ function showNeedLoginDialog(config) {
592
623
  ]
593
624
  });
594
625
  }
595
- function showAlertDialog(response, config = {}, request) {
626
+ function showAlertDialog(response, config = {}, request, extra = {}) {
596
627
  if (isGlobalAlertShow || response == null) {
597
628
  return false;
598
629
  }
@@ -611,7 +642,7 @@ function showAlertDialog(response, config = {}, request) {
611
642
  title: ERROR_TITLE,
612
643
  message: /* @__PURE__ */ React.createElement("div", null, config.content ? config.content : "")
613
644
  };
614
- showConsoleBaseAlertDialog(response, _params, request);
645
+ showConsoleBaseAlertDialog(response, _params, request, extra);
615
646
  return true;
616
647
  }
617
648
  function showAlertDialogWhenNeedLogin(response, config = {}) {
@@ -660,13 +691,42 @@ const errorHandler = (request, error, options) => {
660
691
  );
661
692
  }
662
693
  } else {
663
- showAlertDialog(
664
- error,
665
- {
666
- content: errorMsgHandler(error)
667
- },
668
- request
669
- );
694
+ const errorItems = structuredErrorMessage(error.message);
695
+ if (errorItems && Array.isArray(errorItems) && errorItems.length > 0) {
696
+ errorItems.forEach((item) => {
697
+ try {
698
+ const content = createNoXSS(item.message);
699
+ delete item.message;
700
+ delete item.code;
701
+ showAlertDialog(
702
+ __spreadProps$4(__spreadValues$4({}, error), {
703
+ code: item.code
704
+ }),
705
+ {
706
+ content
707
+ },
708
+ request,
709
+ item
710
+ );
711
+ } catch (e) {
712
+ showAlertDialog(
713
+ error,
714
+ {
715
+ content: errorMsgHandler(error)
716
+ },
717
+ request
718
+ );
719
+ }
720
+ });
721
+ } else {
722
+ showAlertDialog(
723
+ error,
724
+ {
725
+ content: errorMsgHandler(error)
726
+ },
727
+ request
728
+ );
729
+ }
670
730
  }
671
731
  }
672
732
  let errorMessage = error.message;
package/package.json CHANGED
@@ -15,5 +15,5 @@
15
15
  "styled-components": "^5.2.0",
16
16
  "urijs": "^1.19.1"
17
17
  },
18
- "version": "4.5.3"
18
+ "version": "4.5.5"
19
19
  }