"""View-layer validation helper.""" from flask import abort, request from marshmallow import ValidationError from abacus_common_logic.constants.error import ERROR_MISSING_JSON_BODY def validated_request_body(schema=None): """Validate the request body against the given schema.""" body = request.get_json() if not body: abort( code=400, description=ERROR_MISSING_JSON_BODY, ) try: return schema.load(body) except ValidationError as e: abort( code=400, description=e.messages, )