[英]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!');
}
I get response:我得到回应:
{
status: 200,
statusText: 'OK',
headers: {
date: 'Thu, 09 Dec 2021 17:29:29 GMT',
..............
}
And error:和错误:
TypeError: Cannot read properties of undefined (reading 'statusText')
Do you know how I can properly get the value of statusText
and compare it?您知道如何正确获取
statusText
的值并进行比较吗?
Try this:尝试这个:
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.