"""View-layer validation helper.""" from flask import abort, request from marshmallow import ValidationError from royalty_common.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( description=ERROR_MISSING_JSON_BODY, status=400 ) try: return schema.load(body) except ValidationError as e: abort( description=e.messages, status=400 )