@blocklet/launcher-util 2.1.20 → 2.1.22
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/lib/format-error.js +27 -10
- package/package.json +2 -2
package/lib/format-error.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
const
|
|
1
|
+
const formatError = (err) => {
|
|
2
|
+
if (!err) {
|
|
3
|
+
return err;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const { details, errors, response } = err;
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
8
|
+
// graphql error
|
|
9
|
+
if (Array.isArray(errors)) {
|
|
10
|
+
return errors.map((x) => x.message).join('\n');
|
|
6
11
|
}
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
// joi validate error
|
|
14
|
+
if (Array.isArray(details)) {
|
|
15
|
+
const formatted = details.map((e) => {
|
|
16
|
+
const errorMessage = e.message.replace(/["]/g, "'");
|
|
17
|
+
const errorPath = e.path.join('.');
|
|
18
|
+
return `${errorPath}: ${errorMessage}`;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return `Validate failed: ${formatted.join(';')}`;
|
|
10
22
|
}
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
24
|
+
// axios error
|
|
25
|
+
if (response) {
|
|
26
|
+
return (
|
|
27
|
+
response.data.error ||
|
|
28
|
+
`Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`
|
|
29
|
+
);
|
|
15
30
|
}
|
|
16
31
|
|
|
17
|
-
return
|
|
32
|
+
return err.message || err;
|
|
18
33
|
};
|
|
34
|
+
|
|
35
|
+
module.exports = formatError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-util",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.22",
|
|
4
4
|
"description": "Common constants",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constant"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"jest": "^27.5.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "82cfc8d632852ef0dd4d40c9a082f90264345291"
|
|
50
50
|
}
|