try:
x = request.GET['x']
except MultiValueDictError:
return response("Missing user data 'x'", status=404)
try:
y = request.GET['y']
except MultiValueDictError:
return response("Missing user data 'y'", status=404)
def handle_exception(self, exc):
if isinstance(exc, QueryDictKeyError):
# It is an unwise assumption that this is necessarily missing HTTP param,
# but rewriting it in other way would be time consuming (and maybe even more error prone).
return MyErrorResponse({"code": "PAR_1",
"message": "Missing param.",
"field": exc.args[0]})if expected_key is not in request.GET:
return MyErrorResponse(...)if not request.GET.get("expected_key", None):
return MyErrorResponse(...)required = ["one", "two", "three", "four"]
if not all(k in request.GET.keys() for k in required):
return MyErrorResponse(...)
Just because your code repeated in each and every form can be eliminated and we can check it all in one place,
shortening code, eliminating duplication, reducing possibilities
of errors.
--
You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/SIl46zbIdIc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2423f3eb-e656-4084-a9c3-94e1ea41e969%40googlegroups.com.