Created
January 18, 2016 03:32
-
-
Save warrenca/002ec29cf35bf8dc0665 to your computer and use it in GitHub Desktop.
express sendOverride()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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