javascript - How to abort a failing Q promise in Node.JS -


Assume that I am creating a registration stream, and I have something that looks like this:

/ P>

  Q.nfcall (validateNewRegCallback, email, password) .fail (function (err) {console.log ("bad email / pass:" + err); return null;}) .then Function () {console log ("valid!");}) .done ();   

If my registration fails, then I want to capture it, and I will die. Instead, I'm seeing both "bad email / pass" and "valid". Why is this, and how can I stop in the first failure call?

unsuccessful Handler grabs rejected promises, but then a complete Returns the promise ( null in your code), because the error was already handled.? |

So what can you do against this?

  • To revert the error to reject the returning promise it will be the reason for throwing it done .

      Q.nfcall (validateNewRegCallback, email, password) .file (function (err) {console.log ("bad email / pass:" + mistake); throw away;}). Then (function () {console.log ("valid!");}). Done (); Take the error after success callback (which also handles  these  errors in the success callback):  
       Q.nfcall (validateNewRegCallback, email , Password) .then (function () {console.log ("validated!")}}. Fail (function) {console.log ("bad email / pass:" + fault);}) ;    
  • Handling both cases at just one promise - Each method accepts two callbacks:

      Q.nfcall (ValidateNewRegCallback, Email, Password) .done (function () {console.log ("validated!");}, Function (err) {console.log ("bad email / pass:" + err);}   

    You can also use Can. Then (â ?? |, â ?? |) .done () .

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -