2π
β
500s arenβt a good meaningful response. You should be validating just about everything. To keep it DRY you can create helper functions to solve the general problem. Something like:
def validate_request(req, keys):
for key in keys:
if key not in request.data:
raise APIException('request.data missing key "{}"'.format(key))
Edit: Youβll have to handle the exception and return a validation error to wherever the request comes from. If you are trying to be RESTful, then you can use status codes with whatever message, or a JSON response with the validation error, or the like. Depends on your use case.
π€Chris Jacobs
Source:stackexchange.com