as follows, I have two functions written in promis form
function one
verifyGA(type){
let that = this;
return new Promise((resolve,reject) => {
that.$post("/user/verifyGA",{
gaCode:that.gaCode,
captchaType:type
}).then(res=>{
if (!res.code) {
resolve(true)
} else {
reject(res.message)
that.gaError = res.message;
}
})
})
},
function two
checkCode(type){
let that = this;
let bind = this.isEmail ? 32:31;
let Untie = this.isEmail ? 34:33;
let code_type = type == 1 ? bind:Untie;
return new Promise((resolve,reject) => {
that.$post("/user/checkCode",{
code:that.code,
codeType:code_type
}).then(res=>{
if (!res.code) {
resolve(true)
} else {
reject(res.message)
that.codeError = res.message;
}
})
})
},
now my requirement is that when I click the submit button, I call the above two methods to verify whether the two CAPTCHAs are correct, and only if they are correct, I can submit them. So I use Promise.all () to deal with these two functions. I don"t know if this is correct. If it is wrong, how to write it correctly
submit function
confirm(){
let that = this;
Promise.all([this.verifyGA(12),this.checkCode(1)]).then(res=>{
console.log(res);
/* */
}).catch(error=>{
console.log(error);
/* */
})
}
then I found that if the above two function requests fail, the error error thrown in promise.all (). Catch () is the error in the second function, not the first function. This is why, how can I throw errors for all functions?