Catch missing API key field

This commit is contained in:
Kumi 2020-10-12 16:54:45 +02:00
parent 12e6d64b37
commit 44db5af9a8

View file

@ -26,7 +26,7 @@ class APIView(View):
def dispatch(self, request, *args, **kwargs):
try:
APIKey.objects.get(key=request.headers["apikey"])
except APIKey.DoesNotExist:
except (APIKey.DoesNotExist, KeyError):
return JsonResponse({"error": "No valid API key provided"})
return super().dispatch(request, *args, **kwargs)