Merge pull request #3 from ginkgobioworks/fix/error-codes

Respond with the correct error code and headers
This commit is contained in:
Jonatan Nilsson 2016-12-15 12:42:05 +00:00 committed by GitHub
commit d1c6203df5
2 changed files with 13 additions and 11 deletions

View file

@ -22,7 +22,7 @@ if (config.get('bunyan') || config.get(env + ':use_bunyan')) {
output = bunyan.createLogger(settings); output = bunyan.createLogger(settings);
} else { } else {
output = console; output = console;
console.debug = console.log.bind(console); output.debug = console.log.bind(console);
} }
module.exports = output; module.exports = output;

View file

@ -12,7 +12,7 @@ var logger = require('./logger');
var env = config.get('NODE_ENV'); var env = config.get('NODE_ENV');
var spserver = function(settings) { var spserver = function (settings) {
if (!settings) { if (!settings) {
settings = config.get(); settings = config.get();
} }
@ -28,7 +28,7 @@ var spserver = function(settings) {
logger.debug('[REQ] GET:', req.url); logger.debug('[REQ] GET:', req.url);
var startTime = new Date().getTime(); var startTime = new Date().getTime();
var done = function() { var done = function () {
var requestTime = new Date().getTime() - startTime; var requestTime = new Date().getTime() - startTime;
logger.debug('[RES] GET:', req.url, '(' + res.statusCode + ') took', requestTime, 'ms'); logger.debug('[RES] GET:', req.url, '(' + res.statusCode + ') took', requestTime, 'ms');
}; };
@ -36,16 +36,18 @@ var spserver = function(settings) {
res.addListener('finish', done); res.addListener('finish', done);
res.addListener('close', done); res.addListener('close', done);
//return base(req, res);
req.addListener('end', function () { req.addListener('end', function () {
fileServer.serve(req, res, function(e) { fileServer.serve(req, res, function (err) {
if (!e) return; if (err) {
if (e && e.status === 404 && base) { if (err.status === 404 && base) {
return base(req, res); return base(req, res);
} else {
logger.error(err);
res.writeHead(err.status, err.headers);
res.end();
}
} }
logger.error(e);
res.writeHead(404);
res.end();
}); });
}).resume(); }).resume();
}); });