@open-tender/utils 0.1.88 → 0.1.89
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/cjs/utils/errors.d.ts +1 -1
- package/dist/cjs/utils/errors.js +18 -17
- package/dist/esm/utils/errors.d.ts +1 -1
- package/dist/esm/utils/errors.js +18 -17
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const handleCheckoutError: (error: CheckoutError,
|
|
14
|
+
export declare const handleCheckoutError: (error: CheckoutError) => Record<string, string | Record<string, string | Record<string, string>>>;
|
|
15
15
|
export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
|
|
16
16
|
export declare const errMessages: {
|
|
17
17
|
unknown: string;
|
package/dist/cjs/utils/errors.js
CHANGED
|
@@ -75,39 +75,40 @@ const makeFormErrors = (error) => {
|
|
|
75
75
|
return errors;
|
|
76
76
|
};
|
|
77
77
|
exports.makeFormErrors = makeFormErrors;
|
|
78
|
-
const handleCheckoutError = (error
|
|
78
|
+
const handleCheckoutError = (error) => {
|
|
79
79
|
const { detail, params, message } = error || {};
|
|
80
80
|
if (!params || (0, helpers_1.isEmpty)(params))
|
|
81
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
form: detail || message || 'Unknown error. Please contact support.'
|
|
83
|
+
};
|
|
82
84
|
const errObj = Object.entries(params).reduce((obj, error) => {
|
|
83
85
|
const [key, value] = error;
|
|
84
|
-
const
|
|
86
|
+
const errMsg = value.message;
|
|
85
87
|
const [, entity, index, field] = key.split('.');
|
|
86
|
-
const existingEntity = obj[entity]
|
|
88
|
+
const existingEntity = Object.hasOwn(obj, entity) ? obj[entity] : null;
|
|
87
89
|
if (!index) {
|
|
88
|
-
return Object.assign(Object.assign({}, obj), { [entity]:
|
|
90
|
+
return Object.assign(Object.assign({}, obj), { [entity]: errMsg });
|
|
89
91
|
}
|
|
90
92
|
else if (!field) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
94
|
+
return Object.assign(Object.assign({}, obj), { [entity]: Object.assign(Object.assign({}, existingEntity), { [index]: errMsg }) });
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: errMsg } });
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
100
|
else {
|
|
95
|
-
if (existingEntity) {
|
|
96
|
-
const existingIndex = existingEntity[index] ||
|
|
97
|
-
const newIndex =
|
|
101
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
102
|
+
const existingIndex = existingEntity[index] || null;
|
|
103
|
+
const newIndex = existingIndex && typeof existingIndex !== 'string'
|
|
104
|
+
? Object.assign(Object.assign({}, existingIndex), { [field]: errMsg }) : { [field]: errMsg };
|
|
98
105
|
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: newIndex });
|
|
99
106
|
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
100
107
|
}
|
|
101
108
|
else {
|
|
102
|
-
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]:
|
|
109
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]: errMsg } } });
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
|
-
// const newEntity = obj[entity]
|
|
106
|
-
// ? { ...obj[entity], [index]: err }
|
|
107
|
-
// : index
|
|
108
|
-
// ? { [index]: err }
|
|
109
|
-
// : err
|
|
110
|
-
// return { ...obj, [entity]: newEntity }
|
|
111
112
|
}, { form: 'There are one or more errors below' });
|
|
112
113
|
return errObj;
|
|
113
114
|
};
|
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const handleCheckoutError: (error: CheckoutError,
|
|
14
|
+
export declare const handleCheckoutError: (error: CheckoutError) => Record<string, string | Record<string, string | Record<string, string>>>;
|
|
15
15
|
export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
|
|
16
16
|
export declare const errMessages: {
|
|
17
17
|
unknown: string;
|
package/dist/esm/utils/errors.js
CHANGED
|
@@ -68,39 +68,40 @@ export const makeFormErrors = (error) => {
|
|
|
68
68
|
}
|
|
69
69
|
return errors;
|
|
70
70
|
};
|
|
71
|
-
export const handleCheckoutError = (error
|
|
71
|
+
export const handleCheckoutError = (error) => {
|
|
72
72
|
const { detail, params, message } = error || {};
|
|
73
73
|
if (!params || isEmpty(params))
|
|
74
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
form: detail || message || 'Unknown error. Please contact support.'
|
|
76
|
+
};
|
|
75
77
|
const errObj = Object.entries(params).reduce((obj, error) => {
|
|
76
78
|
const [key, value] = error;
|
|
77
|
-
const
|
|
79
|
+
const errMsg = value.message;
|
|
78
80
|
const [, entity, index, field] = key.split('.');
|
|
79
|
-
const existingEntity = obj[entity]
|
|
81
|
+
const existingEntity = Object.hasOwn(obj, entity) ? obj[entity] : null;
|
|
80
82
|
if (!index) {
|
|
81
|
-
return Object.assign(Object.assign({}, obj), { [entity]:
|
|
83
|
+
return Object.assign(Object.assign({}, obj), { [entity]: errMsg });
|
|
82
84
|
}
|
|
83
85
|
else if (!field) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
87
|
+
return Object.assign(Object.assign({}, obj), { [entity]: Object.assign(Object.assign({}, existingEntity), { [index]: errMsg }) });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: errMsg } });
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
else {
|
|
88
|
-
if (existingEntity) {
|
|
89
|
-
const existingIndex = existingEntity[index] ||
|
|
90
|
-
const newIndex =
|
|
94
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
95
|
+
const existingIndex = existingEntity[index] || null;
|
|
96
|
+
const newIndex = existingIndex && typeof existingIndex !== 'string'
|
|
97
|
+
? Object.assign(Object.assign({}, existingIndex), { [field]: errMsg }) : { [field]: errMsg };
|
|
91
98
|
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: newIndex });
|
|
92
99
|
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
93
100
|
}
|
|
94
101
|
else {
|
|
95
|
-
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]:
|
|
102
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]: errMsg } } });
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
|
-
// const newEntity = obj[entity]
|
|
99
|
-
// ? { ...obj[entity], [index]: err }
|
|
100
|
-
// : index
|
|
101
|
-
// ? { [index]: err }
|
|
102
|
-
// : err
|
|
103
|
-
// return { ...obj, [entity]: newEntity }
|
|
104
105
|
}, { form: 'There are one or more errors below' });
|
|
105
106
|
return errObj;
|
|
106
107
|
};
|
package/package.json
CHANGED