]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/api/errors.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / api / errors.py
1 class DocError(Exception):
2     def __init__(self, message, doc):
3         super().__init__(message)
4
5         self.doc = doc
6         """
7         The document returned by the API that brought about this error.
8         """
9
10
11 class APIError(DocError):
12     def __init__(self, doc):
13
14         code = doc.get('error', {}).get('code')
15         message = doc.get('error', {}).get('message')
16
17         super().__init__("{0}:{1}".format(code, message), doc)
18
19         self.code = code
20         """
21         The error code returned by the api -- if available.
22         """
23
24         self.message = message
25         """
26         The error message returned by the api -- if available.
27         """
28
29 class AuthenticationError(DocError):
30     def __init__(self, doc):
31         result = doc['login']['result']
32         super().__init__(result, doc)
33
34         self.result = result
35         """
36         The result code of an authentication attempt.
37         """
38
39
40 class MalformedResponse(DocError):
41     def __init__(self, key, doc):
42
43         super().__init__("Expected to find '{0}' in result.".format(key), doc)
44
45         self.key = key
46         """
47         The expected, but missing key from the API call.
48         """

Community Data Science Collective || Want to submit a patch?