嗨,我試着寫的承諾要求一些下載的功能,但如果我有一個超時我不能處理這個錯誤,我嘗試MENY的例子,但仍然有這個錯誤請求承諾未處理拒絕RequestError:錯誤:ETIMEDOUT
Unhandled rejection RequestError: Error: ETIMEDOUT
at new RequestError (/home/parse/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/home/parse/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/home/parse/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/home/parse/node_modules/request/request.js:186:22)
at emitOne (events.js:101:20)
at Request.emit (events.js:191:7)
at Timeout._onTimeout (/home/parse/node_modules/request/request.js:816:16)
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5)
我的代碼
功能下載:
function downloadPhoto(url,uploadUrl,name){
return new Promise(function(resolve, reject){
rp(url,{timeout:15000},function(e){if(e) reject(e);}).on('error', function(e){return reject(e);}).pipe(fs.createWriteStream(name+'.jpg')).on('finish',() => {
//console.log('done Download photo');
return resolve();
});
});
}
調用這個函數
function sndPht(url,uploadUrl){
return new Promise(function(resolve, reject){
return downloadPhoto(url,uploadUrl,name).then(function(){
..... some logic .....
}).catch(function(err){
return reject(err);
});
}
許多文件我調用函數藍鳥JS地圖:
Promise.map(photos, function(photo) {
if(photo.type === 'photo'){
return sndPht(photo,uploadUrl);
}
},{concurrency: 1});
我該怎麼辦了?
是什麼'sndPht' –
@JaromandaX對不起,UPD後。 – izac
所以,這是對'sndPht'返回的諾言的未處理拒絕,這是問題 –