0
我在我的node.js項目中的以下代碼。異步.eachLimit回調錯誤不叫
async.eachLimit(dbresult, 1, function (record, callback) {
var json = JSON.stringify(record)
var form = new FormData()
form.append('data', json)
form.submit(cfg.server + '/external/api', function (err, res) {
if (err) {
callback(err)
}
if (res.statusCode === 200) {
connection.query('UPDATE selected_photos set synced = 1 WHERE selected_id = "' + record.selected_id + '"', function (err, result) {
if (err) {
console.log(err)
callback(err)
} else {
callback()
}
})
} else {
console.log(res.statusCode)
return callback(err)
}
})
}, function (err) {
// if any of the file processing produced an error, err would equal that error
if (err) {
// One of the iterations produced an error.
// All processing will now stop.
console.log('A share failed to process. Try rerunning the Offline Sync')
process.exit(0)
} else {
console.log('All files have been processed successfully')
process.exit(0)
}
})
}
res.statusCode = 302所以這應該是錯誤的。但錯誤回調從未觸發。如何做到這一點得到它引發的錯誤,使它停止eachLimit和表演的
console.log('A share failed to process. Try rerunning the Offline Sync')
讓我接近。我做了:console.log(res.statusCode) err =錯誤('狀態不正常:'+ res.statusCode) callback(err) –