3 """This module contains custom exceptions that are raised by diaspy.
4 These are not described by DIASPORA* protocol as exceptions that should be
5 raised by API implementations but are specific to this particular implementation.
7 If your program should catch all exceptions raised by diaspy and
8 does not need to handle them specifically you can use following code:
10 # this line imports all errors
11 from diaspy.errors import *
15 except DiaspyError as e:
16 # your error handling code...
24 class DiaspyError(Exception):
25 """Base exception for all errors
31 class LoginError(DiaspyError
):
32 """Exception raised when something
33 bad happens while performing actions
34 related to logging in.
39 class TokenError(DiaspyError
):
43 class DataError(DiaspyError
):
47 class InvalidDataError(DataError
):
51 class KeyMissingFromFetchedData(InvalidDataError
):
55 class UserError(DiaspyError
):
56 """Exception raised when something related to users goes wrong.
61 class InvalidHandleError(DiaspyError
):
62 """Raised when invalid handle is found.
67 class SearchError(DiaspyError
):
68 """Exception raised when something related to search goes wrong.
73 class ConversationError(DiaspyError
):
74 """Exception raised when something related to conversations goes wrong.
79 class AspectError(DiaspyError
):
80 """Exception raised when something related to aspects goes wrong.
85 class PostError(DiaspyError
):
86 """Exception raised when something related to posts goes wrong.
91 class StreamError(DiaspyError
):
92 """Exception raised when something related to streams goes wrong.
97 class SettingsError(DiaspyError
):
98 """Exception raised when something related to settings goes wrong.
103 def react(r
, message
='', accepted
=[200, 201, 202, 203, 204, 205, 206], exception
=DiaspyError
):
104 """This method tries to decide how to react
105 to a response code passed to it. If it's an
106 error code it will raise an exception (it will
107 call `throw()` method.
109 If response code is not accepted AND cannot
110 be matched to any exception, generic exception
111 (DiaspyError) is raised (provided that `exception`
112 param was left untouched).
114 By default `accepted` param contains all HTTP
117 User can force type of exception to raise by passing
120 :param r: response code
122 :param message: message for the exception
124 :param accepted: list of accepted error codes
126 :param exception: preferred exception to raise
127 :type exception: valid exception type (default: DiaspyError)
129 warnings
.warn(DeprecationWarning)
130 if r
in accepted
: e
= None
131 else: e
= DiaspyError
133 if e
is not None: e
= exception
134 throw(e
, message
=message
)
137 def throw(e
, message
=''):
138 """This function throws an error with given message.
139 If None is passed as `e` throw() will not raise
142 :param e: exception to throw
143 :type e: any valid exception type or None
144 :param message: message for exception
147 warnings
.warn(DeprecationWarning)
149 else: raise e(message
)