{"size": 649, "ext": "js", "max_stars_repo_path": "src/middlewares/errorHandler.js", "max_stars_repo_name": "omclabs/express-rest-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/middlewares/errorHandler.js", "max_issues_repo_name": "omclabs/express-rest-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/middlewares/errorHandler.js", "max_forks_repo_name": "omclabs/express-rest-api", "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": 25.96, "max_line_length": 79, "alphanum_fraction": 0.6363636364}
const ApiError = require('../utils/errors');
const logger = require('../configs/logger');
const helpers = require('../utils/helpers');

// eslint-disable-next-line no-unused-vars
module.exports = (err, req, res, next) => {
  logger.error({
    message: `[${err.code}] ${req.method} ${req.originalUrl} ${err.message}`,
  });

  if (err instanceof ApiError) {
    const result = {
      message: err.message,
    };
    res.status(err.code).json(helpers.formatReturn('error', err.code, result));

    return;
  }

  const result = {
    message: 'Oops something went wrong',
  };
  res.status(500).json(helpers.formatReturn('error', 500, result));
};
