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 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
32 """This method tries to decides how to react
33 to a response code passed to it. If it's an
34 error code it will raise an exception (it will
35 call `throw()` method.
37 If response code is not accepted AND cannot
38 be matched to any exception, generic exception
39 (DiaspyError) is raised (provided that `exception`
40 param was left untouched).
42 By default `accepted` param contains all HTTP
45 User can force type of exception to raise by passing
48 :param r: response code
50 :param message: message for the exception
52 :param accepted: list of accepted error codes
54 :param exception: preferred exception to raise
55 :type exception: valid exception type (default: DiaspyError)
57 if r
in accepted
: e
= None
60 if e
is not None: e
= exception
61 throw(e
, message
=message
)
64 def throw(e
, message
=''):
65 """This function throws an error with given message.
66 If None is passed as `e` throw() will not raise
69 :param e: exception to throw
70 :type e: any valid exception type or None
71 :param message: message for exception
75 else: raise e(message
)