@blocklet/payment-react 1.13.261 → 1.13.262

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/es/libs/util.js CHANGED
@@ -64,6 +64,9 @@ export const formatLocale = (locale = "en") => {
64
64
  };
65
65
  export const formatPrettyMsLocale = (locale) => locale === "zh" ? "zh_CN" : "en_US";
66
66
  export const formatError = (err) => {
67
+ if (!err) {
68
+ return "Unknown error";
69
+ }
67
70
  const { details, errors, response } = err;
68
71
  if (Array.isArray(errors)) {
69
72
  return errors.map((x) => x.message).join("\n");
@@ -77,7 +80,7 @@ export const formatError = (err) => {
77
80
  return `Validate failed: ${formatted.join(";")}`;
78
81
  }
79
82
  if (response) {
80
- return response.data.error || `${err.message}: ${JSON.stringify(response.data)}`;
83
+ return response.data?.error || `${err.message}: ${JSON.stringify(response.data)}`;
81
84
  }
82
85
  return err.message;
83
86
  };
package/lib/libs/util.js CHANGED
@@ -111,6 +111,9 @@ exports.formatLocale = formatLocale;
111
111
  const formatPrettyMsLocale = locale => locale === "zh" ? "zh_CN" : "en_US";
112
112
  exports.formatPrettyMsLocale = formatPrettyMsLocale;
113
113
  const formatError = err => {
114
+ if (!err) {
115
+ return "Unknown error";
116
+ }
114
117
  const {
115
118
  details,
116
119
  errors,
@@ -128,7 +131,7 @@ const formatError = err => {
128
131
  return `Validate failed: ${formatted.join(";")}`;
129
132
  }
130
133
  if (response) {
131
- return response.data.error || `${err.message}: ${JSON.stringify(response.data)}`;
134
+ return response.data?.error || `${err.message}: ${JSON.stringify(response.data)}`;
132
135
  }
133
136
  return err.message;
134
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.261",
3
+ "version": "1.13.262",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -91,7 +91,7 @@
91
91
  "@babel/core": "^7.24.5",
92
92
  "@babel/preset-env": "^7.24.5",
93
93
  "@babel/preset-react": "^7.24.1",
94
- "@blocklet/payment-types": "1.13.261",
94
+ "@blocklet/payment-types": "1.13.262",
95
95
  "@storybook/addon-essentials": "^7.6.19",
96
96
  "@storybook/addon-interactions": "^7.6.19",
97
97
  "@storybook/addon-links": "^7.6.19",
@@ -120,5 +120,5 @@
120
120
  "vite-plugin-babel": "^1.2.0",
121
121
  "vite-plugin-node-polyfills": "^0.21.0"
122
122
  },
123
- "gitHead": "30f66652a71168cbd4050639527dc7dbf15b12bb"
123
+ "gitHead": "223f9f888bc1cf70b8ed7ae367a5c27c341df6f3"
124
124
  }
package/src/libs/util.ts CHANGED
@@ -96,6 +96,10 @@ export const formatLocale = (locale = 'en') => {
96
96
  export const formatPrettyMsLocale = (locale: string) => (locale === 'zh' ? 'zh_CN' : 'en_US');
97
97
 
98
98
  export const formatError = (err: any) => {
99
+ if (!err) {
100
+ return 'Unknown error';
101
+ }
102
+
99
103
  const { details, errors, response } = err;
100
104
 
101
105
  // graphql error
@@ -116,7 +120,7 @@ export const formatError = (err: any) => {
116
120
 
117
121
  // axios error
118
122
  if (response) {
119
- return response.data.error || `${err.message}: ${JSON.stringify(response.data)}`;
123
+ return response.data?.error || `${err.message}: ${JSON.stringify(response.data)}`;
120
124
  }
121
125
 
122
126
  return err.message;