Fetching users from aspect works
[diaspy.git] / diaspy / errors.py
index e5a6167d4579f4b0bef3ed967121879712845179..08e5f5ab96e7d8fe614b79a46f78201c1789747d 100644 (file)
@@ -1,5 +1,25 @@
 #!/usr/bin/env python3
 
+"""This module contains custom exceptions that are raised by diaspy.
+These are not described by DIASPORA* protocol as exceptions that should be
+raised by API implementations but are specific to this particular implementation.
+
+If your program should catch all exceptions raised by diaspy and
+does not need to handle them specifically you can use following code:
+
+    # this line imports all errors
+    from diaspy.errors import *
+
+    try:
+        # your code...
+    except DiaspyError as e:
+        # your error handling code...
+    finally:
+        # closing code...
+"""
+
+import warnings
+
 
 class DiaspyError(Exception):
     """Base exception for all errors
@@ -16,8 +36,78 @@ class LoginError(DiaspyError):
     pass
 
 
+class TokenError(DiaspyError):
+    pass
+
+class CSRFProtectionKickedIn(TokenError):
+    pass
+
+
+class DataError(DiaspyError):
+    pass
+
+
+class InvalidDataError(DataError):
+    pass
+
+
+class KeyMissingFromFetchedData(InvalidDataError):
+    pass
+
+
+class UserError(DiaspyError):
+    """Exception raised when something related to users goes wrong.
+    """
+    pass
+
+
+class InvalidHandleError(DiaspyError):
+    """Raised when invalid handle is found.
+    """
+    pass
+
+
+class SearchError(DiaspyError):
+    """Exception raised when something related to search goes wrong.
+    """
+    pass
+
+
+class ConversationError(DiaspyError):
+    """Exception raised when something related to conversations goes wrong.
+    """
+    pass
+
+
+class AspectError(DiaspyError):
+    """Exception raised when something related to aspects goes wrong.
+    """
+    pass
+
+class UserIsNotMemberOfAspect(AspectError):
+    pass
+
+
+class PostError(DiaspyError):
+    """Exception raised when something related to posts goes wrong.
+    """
+    pass
+
+
+class StreamError(DiaspyError):
+    """Exception raised when something related to streams goes wrong.
+    """
+    pass
+
+
+class SettingsError(DiaspyError):
+    """Exception raised when something related to settings goes wrong.
+    """
+    pass
+
+
 def react(r, message='', accepted=[200, 201, 202, 203, 204, 205, 206], exception=DiaspyError):
-    """This method tries to decides how to react
+    """This method tries to decide how to react
     to a response code passed to it. If it's an
     error code it will raise an exception (it will
     call `throw()` method.
@@ -42,6 +132,7 @@ def react(r, message='', accepted=[200, 201, 202, 203, 204, 205, 206], exception
     :param exception: preferred exception to raise
     :type exception: valid exception type (default: DiaspyError)
     """
+    warnings.warn(DeprecationWarning)
     if r in accepted: e = None
     else: e = DiaspyError
 
@@ -59,5 +150,6 @@ def throw(e, message=''):
     :param message: message for exception
     :type message: str
     """
+    warnings.warn(DeprecationWarning)
     if e is None: pass
     else: raise e(message)