如何解决未处理的拒绝类型错误:“侦听器”参数必须是函数类型收到的类型对象
我只想为我的项目创建简单的 Slack 记录器。我的代码在这里;
import { SLACK_CHANNELS } from '@utility/constants/request';
const https = require('https');
export const sendSlackMessage = (messageBody,channel = SLACK_CHANNELS.SAMPLE_CHANNEL,title = 'Error Notifier',icon_emoji = ':bangbang:') => {
messageBody.icon_emoji = icon_emoji;
messageBody.title = title;
messageBody.channel = channel;
try {
messageBody = JSON.stringify(messageBody);
} catch (e) {
throw new Error('Failed to stringify messageBody',e);
}
const webhookURL = 'webhook_url';
// Promisify the https.request
return new Promise((resolve,reject) => {
// general request options,we defined that it's a POST request and content is JSON
const requestOptions = {
method: 'POST',header: {
'Content-Type': 'application/json',},};
// actual request
const req = https.request(webhookURL,requestOptions,(res) => {
let response = '';
res.on('data',(d) => {
response += d;
});
// response finished,resolve the promise with data
res.on('end',() => {
resolve(response);
});
});
// there was an error,reject the promise
req.on('error',(e) => {
reject(e);
});
req.write(messageBody);
req.end();
});
}
我收到了这个错误; 未处理的拒绝(类型错误):“侦听器”参数必须是函数类型。接收类型对象
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。