summaryrefslogtreecommitdiff
path: root/common/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-01-24 19:09:46 -0200
committerdrebs <drebs@leap.se>2014-01-25 09:23:42 -0200
commitc97f48660a1aaad96f7356ac1a5fce6265241e0f (patch)
treef0363977b9c775ef700c99572fa9f730c1388059 /common/src/leap
parent49e7366e3b6dcad7fde6b78ed3c2bffd3b1430e4 (diff)
Improve unauthorized error messages.
Diffstat (limited to 'common/src/leap')
-rw-r--r--common/src/leap/soledad/common/errors.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/common/src/leap/soledad/common/errors.py b/common/src/leap/soledad/common/errors.py
index fc4d106a..446c4c75 100644
--- a/common/src/leap/soledad/common/errors.py
+++ b/common/src/leap/soledad/common/errors.py
@@ -25,14 +25,17 @@ from u1db import errors
from u1db.remote import http_errors
-exceptions = []
-
-
def register_exception(cls):
"""
- A small decorator to make it easier to register exceptions.
+ A small decorator that registers exceptions in u1db maps.
"""
- exceptions.append(cls)
+ # update u1db "wire description to status" and "wire description to
+ # exception" maps.
+ http_errors.wire_description_to_status.update({
+ cls.wire_description: cls.status})
+ errors.wire_description_to_exc.update({
+ cls.wire_description: cls})
+ # do not modify the exception
return cls
@@ -44,6 +47,30 @@ class SoledadError(errors.U1DBError):
#
+# Authorization errors
+#
+
+@register_exception
+class MissingAuthTokenError(errors.Unauthorized):
+ """
+ Exception raised when failing to get authorization for some action because
+ the auth token is missing in the tokens db.
+ """
+
+ wire_description = "missing token"
+ status = 401
+
+@register_exception
+class InvalidAuthTokenError(errors.Unauthorized):
+ """
+ Exception raised when failing to get authorization for some action because
+ the provided token is different from the one in the tokens db.
+ """
+
+ wire_descrition = "token mismatch"
+ status = 401
+
+#
# LockResource errors
#
@@ -156,15 +183,6 @@ class DesignDocUnknownError(SoledadError):
status = 500
-# update u1db "wire description to status" and "wire description to exception"
-# maps.
-for e in exceptions:
- http_errors.wire_description_to_status.update({
- e.wire_description: e.status})
- errors.wire_description_to_exc.update({
- e.wire_description: e})
-
-
# u1db error statuses also have to be updated
http_errors.ERROR_STATUSES = set(
http_errors.wire_description_to_status.values())