SS
Size: a a a
SS
TK
VD
LK
const fieldErrors = {
name: {
error: 'name.exists'
},
surname: {
field: {
error: 'surname.exists',
typeError: 'call.to.api.error',
},
errors: {
error: 123,
field: {
error: 'some.custom.error.from.backend',
},
},
},
};
const replaceErrors = obj => {
const clonedObj = { ...obj };
const entries = Object.entries(clonedObj);
entries.forEach(([key, value]) => {
if (typeof value === "object") {
clonedObj[key] = replaceErrors(value);
} else {
if (typeof clonedObj.error === 'string') {
clonedObj.error = "test";
}
}
});
return clonedObj;
};
function replaceErrors(obj) {
return Object.keys(obj).reduce((acc, key) => {
if (typeof obj[key] === 'object') {
acc[key] = replaceErrors(obj[key]);
} else {
if (key === 'error' && typeof obj[key] === 'string') {
acc.error = 'test';
}
}
return {
...acc,
[key]: acc[key]
};
}, {});
}
LK
LK
LK
function replaceErrors(obj) {
return Object.keys(obj).reduce((acc, key) => {
if (typeof obj[key] === 'object') {
acc[key] = replaceErrors(obj[key]);
} else {
if (key === 'error') {
acc = {
...obj,
error: typeof obj[key] === 'string' ? 'test' : obj[key]
}
}
}
return acc;
}, {});
}
LK
MS
VK
VK
b
VK
SS
IK
LK
LK
IK
LK