Node.jsから@slack/webhook
を使用して送信してみたところエラーが出たので調べてみたらチャンネル名のスペルミスでした。
Improving error conditions for Incoming Webhooksを確認するとレスポンスのステータスコードとエラー文字列で理由が確認できるとのことでした。 ステータスコードは400,403,404,410,500などがあるとのことです。
実行したコード
const { IncomingWebhook } = require('@slack/webhook')
const params = {
channel: '#channel_name',
username: 'webhookbot',
icon_emoji: ':ghost:',
text: 'send from node.js'
}
const webhook = new IncomingWebhook('https://hooks.slack.com/services/xxxxx/xxxxx/xxxxx')
webhook.send(params)
エラー
(node:49295) UnhandledPromiseRejectionWarning: Error: An HTTP protocol error occurred: statusCode = 404
at Object.httpErrorWithOriginal (/xxxxx/node_modules/@slack/webhook/dist/errors.js:35:33)
at IncomingWebhook.send (/xxxxx/node_modules/@slack/webhook/dist/IncomingWebhook.js:51:32)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:49295) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:49295) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:49295) UnhandledPromiseRejectionWarning: Error: An HTTP protocol error occurred: statusCode = 404
at Object.httpErrorWithOriginal (/xxxxx/node_modules/@slack/webhook/dist/errors.js:35:33)
at IncomingWebhook.send (/xxxxx/node_modules/@slack/webhook/dist/IncomingWebhook.js:51:32)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:49295) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:49295) UnhandledPromiseRejectionWarning: Error: An HTTP protocol error occurred: statusCode = 404
at Object.httpErrorWithOriginal (/xxxxx/node_modules/@slack/webhook/dist/errors.js:35:33)
at IncomingWebhook.send (/xxxxx/node_modules/@slack/webhook/dist/IncomingWebhook.js:51:32)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:49295) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)