bbj/src/exceptions.py

55 lines
1.7 KiB
Python
Raw Normal View History

2017-04-02 07:35:58 +00:00
from src.schema import error
class BBJException(Exception):
"""
Base class for all exceptions specific to BBJ. These also
hold schema error objects, reducing the amount of code
required to produce useful errors.
"""
def __init__(self, code, description):
self.schema = error(code, description)
self.description = description
self.code = code
def __str__(self):
return self.description
class BBJParameterError(BBJException):
"""
This class of error holds code 3. This is a general
classification used to report errors on behalf of
the client. It covers malformed or missing parameter
values for endpoints, type errors, index errors, etc.
A complete client should not encounter these and the
descriptions are geared towards client developers
rather than users.
"""
def __init__(self, description):
super().__init__(3, description)
class BBJUserError(BBJException):
"""
This class of error holds code 4. Its description should
be shown verbatim in clients, as it deals with invalid user
actions rather than client or server errors. It is especially
useful during registration, and reporting lack of admin privs
when editing messages.
"""
def __init__(self, description):
super().__init__(4, description)
class BBJAuthError(BBJException):
"""
This class of error holds code 5. Similar to code 4,
these should be shown to users verbatim. Provided when:
* a client tries to post without user/auth_hash pair
* the auth_hash does not match the given user
"""
def __init__(self, description):
super().__init__(5, description)