[Vuejs]-Exit from a block of if statements

0👍

throw an Error and catch (MDN) it outside the if:

try {
  // your if block ... 
  throw new Error('error message');
  // ...
} catch (error) {
   window.$nuxt.error({ 
     statusCode: 500, 
     message: error.message
   });
}

of course, if you got the same error message, just hardcode it and simply throw new Error(); or anything else for that matter

0👍

you can modify your code like below

if(sauhp.length < 1){
                //sauhp is empty and not a bot - proceed
                const token = await this.$recaptcha(formType);
                //Send the token to validate
                let verifyReCaptcha = await axios.get('/api/recaptcha/api/siteverify?secret='+secret+'&response='+token);
                let reCaptchaResponse = verifyReCaptcha.data;
                //Validate the action
                if(reCaptchaResponse.action === formType && reCaptchaResponse.score > 1){
                    console.log('yes great go ahead')
                    return true;
                }
            }
            window.$nuxt.error({ 
                            statusCode: 500, 
                            message: "We've detected a problem in the form submission. Call us, we're here to help."
                        }) 
            }
        },

Leave a comment