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