[英]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.