I am using Flask Restful's reqparse interface for parsing request parameters. I have field for date which is required and for which I have to performing validation
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument('date',type=date_type,required=True,help='date cannot be blank')
args = parser.parse_args()
I have defined custom date_type type for validating that string can be parsed to date using python-dateutil package
def date_type(date_str):
try:
return parser.parse(date_str)
except:
raise ValueError('Not a valid date format')
I want to return appropriate messages, if date field is missing or date is not a valid date but using add_argument, i am only allowed to have only one help message. Does add_argument allow to have different message in case of missing and invalid data type event.