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 UserError(DiaspyError
):
20 """Exception raised when something related to users goes wrong.
25 class InvalidHandleError(DiaspyError
):
26 """Raised when invalid handle is found.
31 class SearchError(DiaspyError
):
32 """Exception raised when something related to search goes wrong.
37 class ConversationError(DiaspyError
):
38 """Exception raised when something related to conversations goes wrong.
43 class AspectError(DiaspyError
):
44 """Exception raised when something related to aspects goes wrong.
49 class PostError(DiaspyError
):
50 """Exception raised when something related to posts goes wrong.
55 class StreamError(DiaspyError
):
56 """Exception raised when something related to streams goes wrong.
61 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
62 """This method tries to decides how to react
63 to a response code passed to it. If it's an
64 error code it will raise an exception (it will
65 call `throw()` method.
67 If response code is not accepted AND cannot
68 be matched to any exception, generic exception
69 (DiaspyError) is raised (provided that `exception`
70 param was left untouched).
72 By default `accepted` param contains all HTTP
75 User can force type of exception to raise by passing
78 :param r: response code
80 :param message: message for the exception
82 :param accepted: list of accepted error codes
84 :param exception: preferred exception to raise
85 :type exception: valid exception type (default: DiaspyError)
87 if r
in accepted
: e
= None
90 if e
is not None: e
= exception
91 throw(e
, message
=message
)
94 def throw(e
, message
=''):
95 """This function throws an error with given message.
96 If None is passed as `e` throw() will not raise
99 :param e: exception to throw
100 :type e: any valid exception type or None
101 :param message: message for exception
105 else: raise e(message
)