I'm struggling with async functions, Axios in particular.
I got a function that passes to a WS two values (the important is 'cod') and based on the http response has to return cod or "".
function checkCod(callback){
axiosCall.get('codecheck.php',{params:{user:usr,cod:cod}})
.then((response)=>{
if(response.status!==200){//if I give an error http response callback argument is ""
console.log("false code");
callback("");
}else{
callback(cod); //if everything goes right callback argument is cod (passed as the WS)
}
})
.catch((error)=>{
console.log(error);
callback(""); //if I give an error http response callback argument is ""
});
}
function codRes(c){
cod=c;
return cod;
};
return checkCod(codRes);
A value is never returned (with 200 or 500 or 400 headers, which are the 3 cases), and I really can't figure out why.
The above code is based on How do I return the response from an asynchronous call? answer...