質問するログイン新規登録

回答編集履歴

1

エラーの処理周りをちょっと修正

2017/12/07 07:22

投稿

miyabi-sun
miyabi-sun

スコア21542

answer CHANGED
@@ -30,7 +30,7 @@
30
30
  }
31
31
  const send_options = {
32
32
  host: 'api.line.me',
33
- path: '/v2/bot/message/' + it.object + '/content',
33
+ path: `/v2/bot/message/${it.object}/content`,
34
34
  headers: {
35
35
  "Content-type": "application/json; charset=UTF-8",
36
36
  "Authorization": " Bearer {" + Token + "}",
@@ -41,7 +41,7 @@
41
41
  var data = [];
42
42
  res
43
43
  .on('data', chunk => { data.push(new Buffer(chunk)) })
44
- .on('error', err => { console.log(err) })
44
+ .on('error', err => { done(err, null) })
45
45
  .on('end', () => {
46
46
  //データが細切れになっているので連結。
47
47
  var result = Buffer.concat(data);
@@ -52,9 +52,10 @@
52
52
  });
53
53
 
54
54
  async.series(functions, (err, results) => {
55
+ if (err) console.error(err);
55
56
  // results内にdoneの第二引数の配列が詰まっているはずなので確認してください。
56
57
  console.log(results);
57
- console.log(results.filter(it => Boolean(it))); // Null除去
58
+ console.log(results.filter(it => it != null)); // Null除去
58
59
  });
59
60
  ```
60
61