adds logger and starts logging errors

This commit is contained in:
Matteo Pagliazzi
2015-11-03 17:47:16 +01:00
parent 5f3e798016
commit 5e73bc9f1c
3 changed files with 30 additions and 3 deletions

View File

@@ -2,13 +2,19 @@
// The error handler middleware that handles all errors
// and respond to the client
let logger = require('../../libs/api-v3/logger');
let errors = require('../../libs/api-v3/errors');
let CustomError = errors.CustomError;
let InternalServerError = errors.InternalServerError;
module.exports = function (err, req, res, next) {
// TODO add logging
// Log the original error with some metadata
let stack = err.stack || err.message || err;
logging.error(stack, {
originalUrl: req.originalUrl,
headers: req.headers,
body: req.body
});
// In case of a CustomError class, use it's data
// Otherwise try to identify the type of error (mongoose validation, mongodb unique, ...)