Axios 获取请求返回承诺而不是 NodeJS 中的状态代码

时间:2021-06-07 16:11:08

标签: javascript node.js axios

msg = {
    "channel": "#the_squad",
    "username": "test ETL Notification",
    "text": "",
    "icon_emoji": ":bell:"
}

async function axiosTest(url) {
    const response = await axios.get(url)
    return response.status
}

let data = axiosTest(urlArray[0]);
data.then( async function(results){
    return await results
})

msg.text = data

console.log(msg)

获取输出:

{
  channel: '#the_squad',
  username: 'test ETL Notification',
  text: Promise { <pending> },
  icon_emoji: ':bell:'
}

期望输出:

{
  channel: '#the_squad',
  username: 'test ETL Notification',
  text: 200,
  icon_emoji: ':bell:'
}

我如何返回所需的输出/处理承诺?该函数已经是异步的,所以我不确定我哪里出错了。 ps 我是 js 新手

0 个答案:

没有答案