from flask_restx.reqparse import RequestParser from werkzeug.exceptions import BadRequest from app_common.const import MALFORMED_DATA, BAD_USER_ROLES class QuarterRequestParser(RequestParser): def parse_args(self, req=None, strict=False): try: return super().parse_args(req=req, strict=strict) except BadRequest as err: error_type = MALFORMED_DATA if 'roles' in err.data.get('errors', {}): error_type = BAD_USER_ROLES err.data.update({'error_type': error_type}) raise err