1
2
3
4
5
6
7 import json
8
9 from apiclient import errors as apiclient_errors
10 from collections import OrderedDict
11
12 -class ApiError(apiclient_errors.HttpError):
14 try:
15 return '; '.join(json.loads(self.content.decode('utf-8'))['errors'])
16 except (KeyError, TypeError, ValueError):
17 return super(ApiError, self)._get_reason()
18
19
21 """Base class for errors accessing Keep services."""
22 - def __init__(self, message='', request_errors=(), label=""):
23 """KeepRequestError(message='', request_errors=(), label="")
24
25 :message:
26 A human-readable message describing what Keep operation
27 failed.
28
29 :request_errors:
30 An iterable that yields 2-tuples of keys (where the key refers to
31 some operation that was attempted) to the error encountered when
32 talking to it--either an exception, or an HTTP response object.
33 These will be packed into an OrderedDict, available through the
34 request_errors() method.
35
36 :label:
37 A label indicating the type of value in the 'key' position of request_errors.
38
39 """
40 self.label = label
41 self._request_errors = OrderedDict(request_errors)
42 if self._request_errors:
43 exc_reports = [self._format_error(*err_pair)
44 for err_pair in self._request_errors.items()]
45 base_msg = "{}: {}".format(message, "; ".join(exc_reports))
46 else:
47 base_msg = message
48 super(KeepRequestError, self).__init__(base_msg)
49 self.message = message
50
57
59 """request_errors() -> OrderedDict
60
61 The keys of the dictionary are described by `self.label`
62 The corresponding value is the exception raised when sending the
63 request to it."""
64 return self._request_errors
65
66
68 - def __init__(self, status_code, reason):
69 self.status_code = status_code
70 self.reason = reason
71
72
95