chg: frontend errorFormating
This commit is contained in:
@@ -68,38 +68,33 @@ export function isEmpty(obj) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Test whether or not an object is empty.
|
||||
* @param {any} obj - The object to test
|
||||
* @returns `true` or `false`
|
||||
*/
|
||||
|
||||
export function formatError(obj) {
|
||||
const errors = [];
|
||||
if (typeof obj === "object" && obj !== null) {
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach((/** @type {Object} */ error) => {
|
||||
Object.keys(error).map((k) => {
|
||||
errors.push({
|
||||
error: error[k],
|
||||
id: Math.random() * 1000,
|
||||
});
|
||||
obj.forEach((error) => {
|
||||
errors.push({
|
||||
field: error.field,
|
||||
key: error.key,
|
||||
id: Math.random() * 1000,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Object.keys(obj).map((k) => {
|
||||
Object.keys(obj).forEach((field) => {
|
||||
errors.push({
|
||||
error: obj[k],
|
||||
field: field,
|
||||
key: obj[field].key,
|
||||
id: Math.random() * 1000,
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
errors.push({
|
||||
error: obj.charAt(0).toUpperCase() + obj.slice(1),
|
||||
field: "general",
|
||||
key: obj,
|
||||
id: 0,
|
||||
});
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user