chg: frontend errorFormating
This commit is contained in:
@@ -68,38 +68,33 @@ export function isEmpty(obj) {
|
|||||||
}
|
}
|
||||||
return true;
|
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) {
|
export function formatError(obj) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
if (typeof obj === "object" && obj !== null) {
|
if (typeof obj === "object" && obj !== null) {
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
obj.forEach((/** @type {Object} */ error) => {
|
obj.forEach((error) => {
|
||||||
Object.keys(error).map((k) => {
|
|
||||||
errors.push({
|
errors.push({
|
||||||
error: error[k],
|
field: error.field,
|
||||||
|
key: error.key,
|
||||||
id: Math.random() * 1000,
|
id: Math.random() * 1000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
Object.keys(obj).map((k) => {
|
Object.keys(obj).forEach((field) => {
|
||||||
errors.push({
|
errors.push({
|
||||||
error: obj[k],
|
field: field,
|
||||||
|
key: obj[field].key,
|
||||||
id: Math.random() * 1000,
|
id: Math.random() * 1000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errors.push({
|
errors.push({
|
||||||
error: obj.charAt(0).toUpperCase() + obj.slice(1),
|
field: "general",
|
||||||
|
key: obj,
|
||||||
id: 0,
|
id: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user