Skip to content

Instantly share code, notes, and snippets.

@warrenca
Created January 18, 2016 03:32
Show Gist options
  • Save warrenca/002ec29cf35bf8dc0665 to your computer and use it in GitHub Desktop.
Save warrenca/002ec29cf35bf8dc0665 to your computer and use it in GitHub Desktop.
express sendOverride()
/**
* sendOverride()
* Override response.send to do nothing when response is already sent
* This is to minimize the error message
*/
function responseSendOverride() {
return function(req,res,next){
var _send = res.send;
var sent = false;
res.send = function(data){
if(sent) {
console.error("Header already sent!");
return;
}
_send.bind(res)(data);
sent = true;
};
next();
}
}
module.exports = responseSendOverride;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment