formsy-react
formsy-react copied to clipboard
Prevent updateInputsWithError to throw error if corresponding component not found
Hi, guys! I found out, that when i pass object with errors to updateInputsWithError
, and there's no corresponding component in my form, an error is thrown.
Here's code snippet responsible for that.
updateInputsWithError = (errors) => {
Object.keys(errors).forEach((name) => {
const component = utils.find(this.inputs, input => input.props.name === name);
if (!component) {
throw new Error(`You are trying to update an input that does not exist. Verify errors object with input names. ${JSON.stringify(errors)}`);
}
....
Wouldn't it be better if warning has been shown, instead of error thrown? Because I don't want my app to stop, when server sends more errors, than my form has?
That's an interesting point. Can you just surround your updateInputsWithError
with a try-catch? The downside to warnings is they can't be caught and handled.
@rkuykendall thank you for your answer! The problem is that some fields may not be updated because of an error
That is a very good point. I think that would be an easy refactor to update all found fields and their errors for the rest. I'll work on it.