3 """This module contains custom exceptions that are raised by diaspy.
4 These are not described by DIASPORA* protocol as exceptions that should be
5 raised by API implementations but are specific to this particular implementation.
7 If your program should catch all exceptions raised by diaspy and
8 does not need to handle them specifically you can use following code:
10 # this line imports all errors
11 from diaspy.errors import *
15 except DiaspyError as e:
16 # your error handling code...
24 class DiaspyError(Exception):
25 """Base exception for all errors
31 class LoginError(DiaspyError
):
32 """Exception raised when something
33 bad happens while performing actions
34 related to logging in.
39 class TokenError(DiaspyError
):
42 class CSRFProtectionKickedIn(TokenError
):
46 class DataError(DiaspyError
):
50 class InvalidDataError(DataError
):
54 class KeyMissingFromFetchedData(InvalidDataError
):
58 class UserError(DiaspyError
):
59 """Exception raised when something related to users goes wrong.
64 class InvalidHandleError(DiaspyError
):
65 """Raised when invalid handle is found.
70 class SearchError(DiaspyError
):
71 """Exception raised when something related to search goes wrong.
76 class ConversationError(DiaspyError
):
77 """Exception raised when something related to conversations goes wrong.
82 class AspectError(DiaspyError
):
83 """Exception raised when something related to aspects goes wrong.
87 class UserIsNotMemberOfAspect(AspectError
):
91 class PostError(DiaspyError
):
92 """Exception raised when something related to posts goes wrong.
97 class StreamError(DiaspyError
):
98 """Exception raised when something related to streams goes wrong.
103 class SettingsError(DiaspyError
):
104 """Exception raised when something related to settings goes wrong.
109 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
110 """This method tries to decide how to react
111 to a response code passed to it. If it's an
112 error code it will raise an exception (it will
113 call `throw()` method.
115 If response code is not accepted AND cannot
116 be matched to any exception, generic exception
117 (DiaspyError) is raised (provided that `exception`
118 param was left untouched).
120 By default `accepted` param contains all HTTP
123 User can force type of exception to raise by passing
126 :param r: response code
128 :param message: message for the exception
130 :param accepted: list of accepted error codes
132 :param exception: preferred exception to raise
133 :type exception: valid exception type (default: DiaspyError)
135 warnings
.warn(DeprecationWarning)
136 if r
in accepted
: e
= None
137 else: e
= DiaspyError
139 if e
is not None: e
= exception
140 throw(e
, message
=message
)
143 def throw(e
, message
=''):
144 """This function throws an error with given message.
145 If None is passed as `e` throw() will not raise
148 :param e: exception to throw
149 :type e: any valid exception type or None
150 :param message: message for exception
153 warnings
.warn(DeprecationWarning)
155 else: raise e(message
)