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
Async validation failing causes Uncaught promise error #1297
Comments
Same error for me using axios. |
Also seeing this. Would really like for the error to be passed down to the Form through props. There is an ^^ solved the error prop issue (the payload wants a _error key/value): |
This problem is still visible in I've tried same example for 5.3.1 version (without any strange errors) http://redux-form.com/5.3.1/#/examples/asynchronous-blur-validation?_k=cbebna maybe it will give some clues how to fix this i v6. |
Still the same. It may even be reproduced with this demo |
Due to inspecting devtools console seems to be that this issue wasn't fixed in rc.5 either :( |
Having this issue with v6.0.2... Seems to come from here:
Once you got the errors and know the promise was rejected, why are you rejecting again? You're at the end of the promise chain so you should just swallow up the error. I would remove this line: |
@Strato could you make a PR please :) |
Potential fix published in |
Unfortunately v6.0.3 doesn't help. Still get uncaught exception in console |
Confirming that the issue still exists on v6.0.5. |
Yayy! Finally! Waiting for new release ) |
Any ETA for when this will be published? |
Published in |
The problem is back in 6.2.1: http://redux-form.com/6.2.1/examples/asyncValidation/ |
Having same problem in v6.2.0 |
same in 6.3.2 |
Was anyone able to find a solution for this? |
Same problem in 6.3.2 |
Solved it, make sure that you are returning the promise in your handleSubmit. I had it |
Thanks @Anarios. For the benefit of anyone else, I did the
|
This is still unfixed in 6.5.0 |
...and can be reproduced on http://redux-form.com/6.5.0/examples/asyncValidation/ Just enter something in the password field and then type "paul" in the user field. Then, while still having the The validation error will show as expected, but there is also a unhandled Promise rejection in the console. |
This currently does not seem to work properly due to a bug in redux-form: redux-form/redux-form#1297 redux-form/redux-form#1682 If/when this bug is fixed, we could consider moving to this format
I've made an interesting find. I have the same problem and have a way to avoid it now.
This produces the error Uncought in Promise even if the underlying Promise resolves (but returns a value). If I change this to:
This gets rid of the error. Apparently returning ANYTHING from the resolved promise results in it being treated as an error. Instead of just treating rejection as an error. I've tested this by changing |
This is how async validation works in practise right now:
Example: function asyncValidate(values) {
// Assume errors is already in Redux Form compatible format.
// Here catch essentially just ignores error if:
// 1) destructuring errors failed in .then
// 2) fetchStuff threw an error, for example if you have custom logic in case fetch() response.ok is false
return fetchStuff(values).then(
({ errors }) => errors || null
).catch(() => null)
} Essentially: the docs are incorrect. You never need to The major "flaw" in the current design is that rejecting is not really handled properly, which is the bug you see. And in general when managing errors in promises you should always I think the To correct the issue with promise usage there are a couple of hard questions:
Related to this I happen to have a case where I can get error and/or warning level validation errors: warning level can be ignored but error level cannot. The current asyncValidate doesn't really support this use case so I have to "manually hack" with component state. It would be nice if the async validation and it's usage of promises and errors is rethought, and then changed if seen worthwhile. |
In case anyone else has the same silly mistake. As outlined in #2269 (comment), if using
Now it works even with async functions:
|
@irisSchaffer i ran into this, too... for subsequent readers, it's worth calling out that ReduxForm doesn't really play well with submitting anything outside of the context of its own components, so i'm ending up (like you) using a higher order function to pass initial values in and then let the form call the returned function and retain access to those values through the closure. kinda funky... i want to dig into this and figure out if there's a more robust or stabler way to use these guys. |
I was getting this error even on submit validation (like @waynebrantley) and was racking my brains for couple of days. I found that SubmissionError I was throwing even was not instanceof SubmissionError... It seems that the reason was how I imported SubmissionError: import SubmissionError from 'redux-form/lib/SubmissionError'; When I changed it to: import { SubmissionError } from 'redux-form'; it started to work as described in documentation. |
I have no problem throwing error but how to return error message back to UI? I use the same function as my submitValidate which works fine and throw the error to UI but with asyncValidate it only throw error in console log but not in UI |
I use this in meteor
just
is fine. Here is my solution export const asyncValidate = values => {
return new Promise((resolve, reject) => {
reject({ yourFieldName: 'your error message' })
})
} credit: the idea from this issue #2021 |
This definitely needs better documentation |
@sebmor PRs are welcome |
The problem is present in v7.0 again. Upgrading to this version produced the error. And after many hours of unsuccessfull attempts, tried to downgrading redux-form to v6.5, and async validation started to work as intended. |
As a solution you can use such kind of hack: render() {
const { handleSubmit } = props;
const onSubmit = e => {
e.preventDefault();
handleSubmit().catch(() => null);
};
return (
<form onSubmit={onSubmit}>
... Also I've created a Pull Request to fix the bug #3227 |
Re-opening as this issue appears still active. |
This expected to be fixed in 7.0.3 🎉. Is someone who was affected by this willing to confirm? |
Yep! Updated redux-form to v7.0.3 and it is working without any problem! |
Also can confirm. The error doesn't appear in 7.0.3 |
Thanks everyone! |
If you still have the error, make sure you actually return a Promise in your submit function: const workingSubmit = (values) => {
return Promise.reject(new SubmissionError({_error: 'test'}))
}
const nonWorkingSubmit = (values) => {
Promise.reject(new SubmissionError({_error: 'test'}))
} The latter will show an uncaught Promise. |
i try to trigger |
I still got the error in 7.0.3 and I did like described in docs for an exchange of a warn (removed the SubmissionError): Broken way: Works but gave me warn of "Expected an object to be thrown": This code is inside an Axios request which validates if the email is registered. |
Here is an example of @erikras can you check it, please? |
+1 |
I'm having the same issue when trying to submit via ActionCreator. So instead of clicking submit button, I'm dispatching submit action, which cause exactly the same error. |
+1
|
I came across the same issue in V 8.1.0. I solved it by writing the AXIOS api call using Async/Await. import axios from 'axios'; const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const asyncValidate = (values /* , dispatch */) => sleep(1000).then(async () => { // simulate server latency export default asyncValidate; |
The link in the docs to rc.3 is broken but you can see this in rc.2
Go to http://redux-form.com/6.0.0-rc.2/examples/asyncValidation/ and fail the validation.
You will get a
undefined:1 Uncaught (in promise) Object {username: "That username is taken"}
errorThe text was updated successfully, but these errors were encountered: