Skip to content

Commit a9c5726

Browse files
authored
Merge pull request #5 from uc-cdis/fix/auth-code
fix(error): fix authn code
2 parents 6309e8a + 5f4a4ff commit a9c5726

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

cdiserrors/__init__.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,43 @@ def __init__(self, file_format, code=400, json=None):
4444
)
4545
super(BaseUnsupportedError, self).__init__(message, code, json)
4646

47+
4748
class AuthError(APIError):
49+
"""
50+
Authorization Error. This is for any case that user
51+
has valid authentication but is unauthorized to access
52+
particular resources
53+
54+
This is deprecated, should use AuthZError explicitly
55+
"""
4856
def __init__(self, message=None, code=403, json=None):
4957
if json is None:
5058
json = {}
51-
auth_message = "You don't have access to this data"
59+
auth_message = "You don't have access to this resource"
5260
if message is not None:
5361
auth_message += ': {}'.format(message)
5462
super(AuthError, self).__init__(auth_message, code, json)
5563

64+
65+
class AuthZError(AuthError):
66+
"""
67+
Authorization Error. This is for any case that user
68+
has valid authentication but is unauthorized to access
69+
particular resources
70+
"""
71+
pass
72+
73+
class AuthNError(APIError):
74+
"""
75+
Authentication Error. This is for any case that user
76+
is not authenticated or authenticated incorrectly
77+
"""
78+
def __init__(self, message=None, code=401, json=None):
79+
if message is not None:
80+
message = "Authentication Error: {}".format(message)
81+
super(AuthNError, self).__init__(message, code, json)
82+
83+
5684
class InvalidTokenError(AuthError):
5785
def __init__(self):
5886
self.message = (
@@ -61,25 +89,25 @@ def __init__(self):
6189
)
6290
self.code = 403
6391

92+
6493
class InternalError(APIError):
6594
def __init__(self, message=None, code=500):
6695
self.message = "Internal server error"
6796
if message:
6897
self.message += ': {}'.format(message)
6998
self.code = code
7099

71-
class NotFoundError(APIError):
72-
def __init__(self, message):
73-
super(NotFoundError, self).__init__(message, 404, None)
74-
75100

76101
class ServiceUnavailableError(APIError):
77102
def __init__(self, message, code=503):
78103
self.message = message
79104
self.code = code
105+
106+
80107
class ParsingError(Exception):
81108
pass
82109

110+
83111
class SchemaError(Exception):
84112
def __init__(self, message, e=None):
85113
if e:

0 commit comments

Comments
 (0)