@riosst100/pwa-marketplace 1.1.6 → 1.1.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "1.1.6",
4
+ "version": "1.1.7",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -12,5 +12,6 @@ module.exports = componentOverrideMapping = {
12
12
  [`@magento/peregrine/lib/store/actions/user/asyncActions.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js',
13
13
  [`@magento/peregrine/lib/talons/SignIn/signIn.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js',
14
14
  [`@magento/peregrine/lib/talons/SignIn/useSignIn.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js',
15
- [`@magento/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js'
15
+ [`@magento/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js',
16
+ [`@magento/peregrine/lib/util/deriveErrorMessage.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/util/deriveErrorMessage.js'
16
17
  };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Maps an error to a string message
3
+ *
4
+ * @param {Error} error the error to map
5
+ * @return {String} error message
6
+ */
7
+
8
+ const toString = (error, defaultErrorMessage) => {
9
+ const { graphQLErrors, message } = error;
10
+
11
+ if (graphQLErrors && graphQLErrors.length) {
12
+ return graphQLErrors.map(({ message }) => message).join(', ');
13
+ } else {
14
+ if (defaultErrorMessage) {
15
+ return defaultErrorMessage;
16
+ }
17
+ }
18
+
19
+ return message;
20
+ };
21
+
22
+ /**
23
+ * A function to derive an error string from an array of errors.
24
+ */
25
+ export const deriveErrorMessage = (errors, defaultErrorMessage = '') => {
26
+ const errorCollection = [];
27
+ for (const error of errors) {
28
+ if (error) {
29
+ errorCollection.push(toString(error, defaultErrorMessage));
30
+ }
31
+ }
32
+
33
+ return errorCollection.join(', ');
34
+ };