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 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
20 """This method tries to decides how to react
21 to a response code passed to it. If it's an
22 error code it will raise an exception (it will
23 call `throw()` method.
25 If response code is not accepted AND cannot
26 be matched to any exception, generic exception
27 (DiaspyError) is raised (provided that `exception`
28 param was left untouched).
30 By default `accepted` param contains all HTTP
33 User can force type of exception to raise by passing
36 :param r: response code
38 :param message: message for the exception
40 :param accepted: list of accepted error codes
42 :param exception: preferred exception to raise
43 :type exception: valid exception type (default: DiaspyError)
45 if r
in accepted
: e
= None
48 if e
is not None: e
= exception
49 throw(e
, message
=message
)
52 def throw(e
, message
=''):
53 """This function throws an error with given message.
54 If None is passed as `e` throw() will not raise
57 :param e: exception to throw
58 :type e: any valid exception type or None
59 :param message: message for exception
63 else: raise e(message
)