4 class DiaspyError(Exception):
5 """Base exception for all errors
11 class LoginError(DiaspyError
):
12 """Exception raised when something
13 bad happens while performing actions
14 related to logging in.
19 class TokenError(Exception):
23 class UserError(DiaspyError
):
24 """Exception raised when something related to users goes wrong.
29 class InvalidHandleError(DiaspyError
):
30 """Raised when invalid handle is found.
35 class SearchError(DiaspyError
):
36 """Exception raised when something related to search goes wrong.
41 class ConversationError(DiaspyError
):
42 """Exception raised when something related to conversations goes wrong.
47 class AspectError(DiaspyError
):
48 """Exception raised when something related to aspects goes wrong.
53 class PostError(DiaspyError
):
54 """Exception raised when something related to posts goes wrong.
59 class StreamError(DiaspyError
):
60 """Exception raised when something related to streams goes wrong.
65 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
66 """This method tries to decides how to react
67 to a response code passed to it. If it's an
68 error code it will raise an exception (it will
69 call `throw()` method.
71 If response code is not accepted AND cannot
72 be matched to any exception, generic exception
73 (DiaspyError) is raised (provided that `exception`
74 param was left untouched).
76 By default `accepted` param contains all HTTP
79 User can force type of exception to raise by passing
82 :param r: response code
84 :param message: message for the exception
86 :param accepted: list of accepted error codes
88 :param exception: preferred exception to raise
89 :type exception: valid exception type (default: DiaspyError)
91 if r
in accepted
: e
= None
94 if e
is not None: e
= exception
95 throw(e
, message
=message
)
98 def throw(e
, message
=''):
99 """This function throws an error with given message.
100 If None is passed as `e` throw() will not raise
103 :param e: exception to throw
104 :type e: any valid exception type or None
105 :param message: message for exception
109 else: raise e(message
)