Q&A

when I bot.push message to line, it will fail. How can I deal with it?

前提・実現したいこと

発生している問題・エラーメッセージ

(node:15628) UnhandledPromiseRejectionWarning: FetchError: request to https://ap i.line.me/v2/bot/message/push failed, reason: connect ETIMEDOUT 61.71.96.84:443 at ClientRequest.<anonymous> (C:\aircooler\node_modules\node-fetch\lib\index .js:1461:11) at ClientRequest.emit (events.js:315:20) at TLSSocket.socketErrorListener (_http_client.js:469:9) at TLSSocket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) (Use node --trace-warnings ... to show where the warning was created) (node:15628) 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 termin ate the node process on unhandled promise rejection, use the CLI flag --unhandl ed-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejecti ons_mode). (rejection id: 1) (node:15628) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr ecated. In the future, promise rejections that are not handled will terminate th e Node.js process with a non-zero exit code.

該当のソースコード

bot.push(resultemployee[j].uid,"HH");

試したこと

補足情報(FW/ツールのバージョンなど)

  • 0
  • 2
  • 1829
  • twitter facebook

FetchError: request to https://api.line.me/v2/bot/message/push failed, reason: c onnect ETIMEDOUT 61.71.96.84:443 at ClientRequest.<anonymous> (C:\aircooler\node_modules\node-fetch\lib\index .js:1461:11) at ClientRequest.emit (events.js:315:20) at TLSSocket.socketErrorListener (_http_client.js:469:9) at TLSSocket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) { type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

it happened again. I use try catch expression

  • 0

Hmm. The log you provided doesn't give much information. I only see one word ETIMEDOUT which means that the connection can't be established or the server doens't response in time which cause the timeout error.

If you've already checked that your connection is good. Could you correcly handle the promise by implementing .then() and .catch() and post the log that show the actual error again so we can understand your situation more.

Something like this.

bot.push(resultemployee[j].uid,"HH").then(() => {
	console.log("Success")
}).catch(e => {
	console.log(e)
})
  • 0
Are you sure? question.vm