{"size": 447, "ext": "js", "max_stars_repo_path": "packages/api/@infra/middleware/m-validate-req.js", "max_stars_repo_name": "mtsmachado8/nodejsBoilerplate", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/api/@infra/middleware/m-validate-req.js", "max_issues_repo_name": "mtsmachado8/nodejsBoilerplate", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/api/@infra/middleware/m-validate-req.js", "max_forks_repo_name": "mtsmachado8/nodejsBoilerplate", "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": 27.9375, "max_line_length": 123, "alphanum_fraction": 0.6733780761}
import InvalidRequest from '../error/invalid-request-400'



export default (validator) => {
	return (req, res, next) => {

		if(!req.body)
			throw new InvalidRequest(`(${Object.keys(req.route.methods)} ${req.originalUrl}) The body of the request is not valid`);

		const { error } = validator(req.body);
		if(error)
			throw new InvalidRequest(`(${Object.keys(req.route.methods)} ${req.originalUrl}) ${error.details[0].message}`);
		next();
	}
}