Check headers have not already been sent in errorHandler #532

Closed
wants to merge 1 commit into
from
@@ -70,7 +70,9 @@ exports = module.exports = function errorHandler(){
var error = { message: err.message, stack: err.stack };
for (var prop in err) error[prop] = err[prop];
var json = JSON.stringify({ error: error });
- res.setHeader('Content-Type', 'application/json');
+ if (!res.headerSent) {
+ res.setHeader('Content-Type', 'application/json');
+ }
res.end(json);
// plain text
} else {