发送重复命中后无法设置标题

我使用快递4.x节点

我的app.js代码包括

// add generic library to global space global._generic = generic; connection.connect(function(err, db) { if (err) { console.error('error connecting: ' + err.stack); } else { connection.query('USE hakka'); var attachDB = function(req, res, next) { req.db = connection; console.log("Attached DB to req variable. Now moving for next middleware...\n"); next(); }; var requireLogin = function(req, res, next) { common.checkIdandToken(req, res, next); } var beforeRender = function(req, res, next) { _generic.res = res; baseController.beforeRender(req, res, next); } app.post('/api/v1/user', attachDB, beforeRender, function(req, res, next) { user.register(req, res, next); }); app.listen(app.get('port'), function() { console.log('Express server listening on port ' + app.get('port') + '...\n'); }); } }); 

而对于我的模型文件中的错误,我的代码是:

 if (err) { _generic.res.status(err.errno).send({ success: false, message: err.message }); } 

大多数时候它工作正常。 但是当我重复点击非常快然后它给了我

错误:发送后无法设置标题。

PS:

注册方法:

 register: function(req, res, next) { var self = this; UserModel.setDB(req.db); console.log(req.body); UserModel.register(req.body, function(err, result) { if (result.affectedRows > 0) { res.status(200).send(self.createResponse({ token: token, userid: sessionData.user_id }, { success: true, message: "User has been registerd successfully" })); console.log("User has been registerd successfully...\n"); } else { res.status(499).send(self.createResponse({}, { success: false, message: "User can not be registered" })); console.log("User can not be registered...\n"); } }); } 

UserModel.register:

 register: function(data, callback) { var self = this; var userid = SOMERANDOMID; var post = { id: userid, first_name: first_name, last_name: last_name, phone: data.phone, user_status_id: 1 }; var query = self.db.query('INSERT INTO users SET ?', post, function(err, result, fields) { if (err) { _generic.res.status(err.errno).send( self.createResponse({}, { success: false, message: err.message })); console.log(err.message); return false; } callback(err, result); }); } 

电话号码在数据库中是唯一的

当使用相同的电话号码时,产生的响应是:

 { "status": { "success": false, "message": "ER_DUP_ENTRY: Duplicate entry '9898989898' for key 'Phone'" } } 

当我用相同的凭据再次击中它时,我得到了相同的回应。 但是当我做得很快,重复性的命中

错误:发送后无法设置标题。

       

网上收集的解决方案 "发送重复命中后无法设置标题"