{"size": 720, "ext": "js", "max_stars_repo_path": "app/error/handler.js", "max_stars_repo_name": "dinukaw007/dad-dams-backend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/error/handler.js", "max_issues_repo_name": "dinukaw007/dad-dams-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/error/handler.js", "max_forks_repo_name": "dinukaw007/dad-dams-backend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 17.5609756098, "max_line_length": 68, "alphanum_fraction": 0.6569444444}
/**
 * Copyrights 2020 ImitiLabs Pvt Ltd.
 * All Rights Reserved.
 *
 * These material are unpublished, proprietary, confidential source
 * code of ImitiLabs and constitute a TRADE

 *
 .
 *
 */
"use strict";

const formatter = require('./formatter');
const LoggingUtils = require('./../../externals/log/logging_utils');

/**
 * Handle error.
 *
 * @param err
 * @param req
 * @param res
 * @param next
 * @private
 */
function handle(err, req, res, next) {

    let formattedError = formatter.format(err);
    const logger = new LoggingUtils('handler');

    logger.error(err.stack);
    res.status(formattedError.code).json(formattedError.message);

    next();
}


module.exports = (app) => {
    app.use(handle);
};
