Browse Source

add status code logging to all the places

add-status-code-logging
Stephen Hess 8 years ago
parent
commit
7a4c523799
  1. 2
      middleware/404.js
  2. 2
      middleware/500.js
  3. 3
      middleware/sendJSON.js

2
middleware/404.js

@ -1,7 +1,9 @@
const logger = require('pelias-logger').get('api');
// handle not found errors // handle not found errors
function middleware(req, res) { function middleware(req, res) {
res.header('Cache-Control','public'); res.header('Cache-Control','public');
logger.info('status code', 404);
res.status(404).json({ error: 'not found: invalid path' }); res.status(404).json({ error: 'not found: invalid path' });
} }

2
middleware/500.js

@ -7,6 +7,8 @@ function middleware(err, req, res, next) {
var error = (err && err.message) ? err.message : err; var error = (err && err.message) ? err.message : err;
if( res.statusCode < 400 ){ res.status(500); } if( res.statusCode < 400 ){ res.status(500); }
logger.info('status code', res.statusCode);
res.json({ error: typeof error === 'string' ? error : 'internal server error' }); res.json({ error: typeof error === 'string' ? error : 'internal server error' });
} }

3
middleware/sendJSON.js

@ -1,6 +1,7 @@
var check = require('check-types'), var check = require('check-types'),
es = require('elasticsearch'), es = require('elasticsearch'),
exceptions = require('elasticsearch-exceptions/lib/exceptions/SupportedExceptions'); exceptions = require('elasticsearch-exceptions/lib/exceptions/SupportedExceptions');
const logger = require('pelias-logger').get('api');
// create a list of regular expressions to match against. // create a list of regular expressions to match against.
// note: list created when the server starts up; for performance reasons. // note: list created when the server starts up; for performance reasons.
@ -60,6 +61,8 @@ function sendJSONResponse(req, res, next) {
}); });
} }
logger.info('status code', statusCode);
// respond // respond
return res.status(statusCode).json(res.body); return res.status(statusCode).json(res.body);
} }

Loading…
Cancel
Save