Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent updateInputsWithError to throw error if corresponding component not found #132

Open
bamaboy opened this issue Jan 20, 2019 · 3 comments

Comments

@bamaboy
Copy link

bamaboy commented Jan 20, 2019

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?

@bamaboy bamaboy changed the title Prevent updateInputsWithError to throw error if component not found Prevent updateInputsWithError to throw error if corresponding component not found Jan 20, 2019
@rkuykendall
Copy link
Member

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.

@bamaboy
Copy link
Author

bamaboy commented Feb 3, 2020

@rkuykendall thank you for your answer!
The problem is that some fields may not be updated because of an error

@rkuykendall
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants