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
Both then and catch executing in same call #199
Comments
I have the same error. Both then and catch executing in same call |
I am also getting this error. Is there an explanation for this? |
Basically it has to do with how promises works: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate. |
I had the same issue and mine was to do with having |
tomasswood this should not be the case actually. so actually there is no any difference if write .catch first or .then |
@greenzeal there is difference. this is strange, but the order does matter. |
Yes, I was mistaken, there is a order in promises. First to use .then after .catch |
This just happens to me and my problem was (correct me if I'm wrong) that any kind of error you have inside the Example:
|
@dacastro4 THANK YOU! Was pulling my hair out trying to figure out why my request kept catching when it was successful. Re-read through my .then and found a bug 👍 |
@dacastro4 Thank you, my error was in the then execution. Fixed the error in the function that was called by the then statement and the problem was resolved. |
@dacastro4 Thank you so much, you're the man! |
My problem was that I didn't need result in
And instead of being a lambda func declaration in |
thanks. |
I see several people have given a thumb's up to @dacastro4 's comment, could anyone please care to explain how his comment helped you guys with your specific situations? Am looking at the answer but I don't understand how to use it to prevent my |
I think it means that what could be happening, is that maybe there's an error in the "then" block, for what the "catch" block is being excecuted, and that being the reason why both blocks get excecuted. If that is true, doing console.log(error) in the "catch" block should show details. In my case that helped solve the problem. |
I'm doing this call:
I'm calling this exactly once. I get a 200 OK response,
then
block executes, withresponse
being an object I would normally expect. Right after thatcatch
executes, response being a string:Closing: my bad, it was an error somewhere very far in the code, still trying to figure out how it made it into the promise...
The text was updated successfully, but these errors were encountered: