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