This is the current code and what I've come up with:
function getToken() {
return new Promise(async (resolve, reject) => {
try {
let res = await fetch(url);
if (res.status === 418) {
setTimeout(getToken, 1000);
} else {
let token = await res.text();
console.log("1", token);
resolve(token);
}
} catch(e) {
reject(e);
}
});
}
async function test() {
let token = await getToken();
console.log("2", token);
}
test();
It logs 1 <token>
but it doesn't log the other part like its supposed to (2 <token>
). Is there something I'm missing or doing wrong?