From dd47fcc8281c25397b7bbac995cca8baeb52ca8f Mon Sep 17 00:00:00 2001 From: "tao.takashi" Date: Sun, 10 Aug 2008 22:26:34 +0000 Subject: [PATCH] added proposal for exceptions. not wired yet just defined. Many are missing but probably should be defined inside the own subpackage. --- pyogp/lib/base/exc.py | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 pyogp/lib/base/exc.py diff --git a/pyogp/lib/base/exc.py b/pyogp/lib/base/exc.py new file mode 100644 index 0000000..6f12853 --- /dev/null +++ b/pyogp/lib/base/exc.py @@ -0,0 +1,113 @@ +""" +Exceptions for the pyogp library + +""" + + +class Error(Exception): + """base exception for all pyogp related exceptions""" + + +#### Network errors + +class NetworkError(Error): + """general network exception""" + +class ResourceNotFound(NetworkError): + """raised if a resource couldn't be found + + the URL to that resource is stored inside a ``url`` attribute. + + """ + def __init__(self, url = ''): + self.url = url + +class ResourceError(NetworkError): + """raised if any other error occurred (usually a 500) + + contains ``url`` to the resource and ``code`` and ``message`` and ``body`` + + """ + + def __init__(self, url='', code='', message='', body=''): + self.url = url + self.code = code + self.message = message + self.body = body + + + +### Serialization errors + +class SerializationError(Error): + """serialization related exceptions""" + + + +### Deserialization errors + +class DeserializationError(Error): + """deserialization related exception""" + +class DeserializerNotFound(DeserializationError): + """raised if a deserializer for a certain content type couldn't be found + + stores the content type inside a ``content_type`` attribute. + """ + + def __init__(self, content_type=''): + self.content_type = content_type + +class DeserializationFailed(DeserializationError): + """raised if a deserializer couldn't deserialize a payload + + stores the payload inside a ``payload`` attribute and the error message + inside a ``reason`` attribute. + """ + + def __init__(self, payload='', reason=''): + self.payload = payload + self.reason = reason + + + +### Message System related errors + +class MessageSystemError(Error): + """message system related exception""" + + + +########################## +### high level exceptions +########################## + +### Agent Domain related errors + +class AgentDomainError(Error): + """base exception for all errors which can occur on an agent domain""" + +class UserNotFound(AgentDomainError): + """user couldn't be found + + This exception stores the credentials used inside a ``credentials`` attribute + """ + + def __init__(self, credentials = None): + """initialize this exception""" + self.credentials = credentials + + +class UserNotAuthorized(AgentDomainError): + """an error raised in case a user couldn't be authorized + + stores the credentials used inside a ``credentials`` attribute + + """ + + def __init__(self, credentials = None): + """initialize this exception""" + self.credentials = credentials + + +class \ No newline at end of file