2015-06-11 180 views
0

所以我在async.each裏面使用request,並且在調用了一些請求之後,它給了我{{Error:socket hang up] code:'ECONNRESET'}。任何想法我做錯了什麼?{[Error:socket hang up] code:'ECONNRESET'}

async.eachSeries(videos, function (video, next) { 
    if (initialVideosObj[video.id] == false) { 
     var url = config.youtubeApiUrl + "videos?part=contentDetails,snippet,player&key=" + config.youtubeKey + "&regionCode=" + config.regionCode + "&id=" + video.id 
     request(url, function (error, response, body) { 
      if (error) { 
       console.error("ERROR:", error, url);// afet a few requests it gives me { [Error: socket hang up] code: 'ECONNRESET' }, but the funny thing is that the logged url has no problem when I call it manually! 
       next(error); 
      } else if (response.statusCode == 200) { 
       var parsedVideoData = JSON.parse(body); 
       video["duration"] = convertDuration(parsedVideoData.items[0].contentDetails.duration); 
       video["yt_subscribe_id"] = parsedVideoData.items[0].snippet.channelId;               
       next(); 
      } 
     }); 
    } else { 
     setImmediate(next);//Since there is no async operation I use setImmediate! 
    } 
}, function (err) { 
    if (err) { 
     console.error(err.stack, err); 
    } else {             
     console.log("Done") 
    } 
}); 

更新:

這是錯誤堆棧我:

{ [Error: socket hang up] code: 'ECONNRESET' } 
/myProj/node_modules/longjohn/dist/longjohn.js:185 
     throw e; 
      ^
/myProj/getVideo.js:207:71,done (/myProj/node_modules/async/lib/async.js:126:15),/myProj/node_modules/async/lib/async.js:32:16,/myProj/getVideo.js:141:45,Request._callback (/myProj/getVideo.js:399:13),self.callback (/myProj/node_modules/request/request.js:354:22),Request.emit (events.js:107:17),Request.onRequestError (/myProj/node_modules/request/request.js:1011:8) 
+0

您可以使用https://github.com/mattinsler/longjohn獲取將包含異步操作並顯示堆棧跟蹤的長堆棧跟蹤。 –

+0

它是如何工作的?我應該只安裝並需要它嗎?就這樣?文檔沒有任何例子! – user385729

+0

嘿@KietThanhVo我現在增加了錯誤堆棧; – user385729

回答