簡體   English   中英

解析來自 JSON 響應的響應

[英]Parse responses from JSON response

async sendMessage(message) {
    const slackEndpoint = 'https://hooks.slack.com/services/........';
    return await axios.post(slackEndpoint,
      {text: message})
      .catch((error) => console.log(error));
  }

let response = await this.sendMessage(message);
this.logger.info('Sending Slack message for amount threshold: ' + message);
console.log("!!!!!!!!!!!!! ", response.statusText )

if (response.statusText == 'OK') {
  this.logger.info('sent');
}
else {
  this.logger.error('NOT send!');
}

我得到回應:

{
  status: 200,
  statusText: 'OK',
  headers: {
    date: 'Thu, 09 Dec 2021 17:29:29 GMT',
  ..............
}

和錯誤:

TypeError: Cannot read properties of undefined (reading 'statusText')

您知道如何正確獲取statusText的值並進行比較嗎?

嘗試這個:

async sendMessage(message) {
    const slackEndpoint = 'https://hooks.slack.com/services/........';
    return await axios.post(slackEndpoint,
      {text: message})
      .then(response => response)
      .catch((error) => console.log(error));
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM