{"size": 382, "ext": "js", "max_stars_repo_path": "src/utils/format-validation-errors.js", "max_stars_repo_name": "fazlerabby07/task-api", "max_stars_repo_stars_event_min_datetime": "2019-05-21T12:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-30T10:18:52.000Z", "max_issues_repo_path": "src/utils/format-validation-errors.js", "max_issues_repo_name": "fazlerabby07/task-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/format-validation-errors.js", "max_forks_repo_name": "fazlerabby07/task-api", "max_forks_repo_forks_event_min_datetime": "2019-05-21T12:59:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-05T05:20:58.000Z"}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": 5, "avg_line_length": 21.2222222222, "max_line_length": 57, "alphanum_fraction": 0.6020942408}
const customErr = require('./err');

module.exports = error => {
  if (error.name === 'ValidationError') {
    for (const err in error.errors) {
      if (error.errors.hasOwnProperty(err)) {
        return customErr(error.errors[err].message, 422);
      }
    }
  }

  if (error.name === 'MongoError') {
    return customErr('Email allready exists!', 422);
  }

  return error;
};
