javascript - Async .eachLimit callback Error not called -
i following code in node.js project.
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 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 of file processing produced error, err equal error if (err) { // 1 of iterations produced error. // processing stop. console.log('a share failed process. try rerunning offline sync') process.exit(0) } else { console.log('all files have been processed successfully') process.exit(0) } }) }
res.statuscode = 302 should error out. the error callback never triggered. how trigger error stops eachlimit , shows the
console.log('a share failed process. try rerunning offline sync')
you have:
if (err) {
in first line of form submit handler. after that, sure there no error. when check response statuscode
, try call error, calling empty value. why not error when checking in final callback function.
try create new error('status not ok: ' + res.statuscode)
when calling form submit handler.
Comments
Post a Comment