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