From 27fdb10cbdc108e187b32cf0cbc23a8d215bfa6f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 4 Oct 2012 15:52:27 -0400 Subject: [PATCH] Return clean invalid user errors using the API. (imported from commit 2f1687cbe8797ce42e66b340e87400720acd4054) --- zephyr/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zephyr/views.py b/zephyr/views.py index a98cf7a6af..1b08fb1050 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -46,7 +46,10 @@ def api_key_required(view_func): # decorator ordering right. if request.method != "POST": return HttpResponseBadRequest('This form can only be submitted by POST.') - user_profile = UserProfile.objects.get(user__email=request.POST.get("email")) + try: + user_profile = UserProfile.objects.get(user__email=request.POST.get("email")) + except UserProfile.DoesNotExist: + return json_error("Invalid user") if user_profile is None or request.POST.get("api-key") != user_profile.api_key: return json_error('Invalid API user/key pair.') return view_func(request, user_profile, *args, **kwargs)