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) –