Log only exceptions that are unexpected

ObjectDoesNotExist and TypeError exceptions are expected to be raised
and thus does not need to be logged.

Issue: HIC-199
Change-Id: Ic4d305f72d69dfb6929047a6c7be7ff7f1e54a92
diff --git a/crashreports/permissions.py b/crashreports/permissions.py
index 3d953eb..8b10eb9 100644
--- a/crashreports/permissions.py
+++ b/crashreports/permissions.py
@@ -1,6 +1,7 @@
 """Authorization permission classes for accessing the API."""
 import logging
 
+from django.core.exceptions import ObjectDoesNotExist
 from rest_framework.permissions import BasePermission
 from crashreports.models import Device
 
@@ -17,7 +18,12 @@
     """
     try:
         device = Device.objects.get(user=user)
+    except (ObjectDoesNotExist, TypeError):
+        # If the device does not exist or type of the given user is not
+        # correct, False is returned.
+        return False
     except Exception as exception:  # pylint: disable=broad-except
+        # All other exceptions are logged and False is returned.
         logging.exception(exception)
         return False
     if uuid == device.uuid: