I've written a little code snipped for a http request. After I realized request
is async, I rewrote my code with a promise. But it's telling me that the promise is pending. I have absolute no idea why it is wrong. Here my code:
function verifyUser(uname,pword){
var options = {
url: 'CENSORED',
method: 'POST',
headers: headers,
form: {'Username':uname, 'Password':pword, 'Key':key},
json:true
}
return new Promise((r,j) => request(options,(error,response,body)=>{
if(error){
console.log("[ERROR] Promise returned error");
throw j(error);
}
r(body);
}))
}
async function receiveWBBData(uspass,passwd){
const data = await verifyUser(uspass,passwd);
return data;
}
var test1 = receiveWBBData("r0b","CENSORED");
console.log(test1);`
Thanks in advance!