tweaks eslint rules, fixes gulp-eslint, adds some comments

This commit is contained in:
Matteo Pagliazzi
2015-11-04 18:50:08 +01:00
parent 235f1977ba
commit 3135613be3
7 changed files with 19 additions and 15 deletions

View File

@@ -1,21 +1,22 @@
'use strict';
// The error handler middleware that handles all errors
// 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) {
module.exports = function errorHandlerMiddleware (err, req, res, next) {
// Log the original error with some metadata
let stack = err.stack || err.message || err;
logger.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, ...)
// If we can't identify it, respond with a generic 500 error