1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """Errors for the library.
16
17 All exceptions defined by the library
18 should be defined in this file.
19 """
20
21 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
22
23 import json
24
25 from oauth2client import util
26
27
28 -class Error(Exception):
29 """Base error for this module."""
30 pass
31
34 """HTTP data was invalid or unexpected."""
35
36 @util.positional(3)
37 - def __init__(self, resp, content, uri=None):
38 self.resp = resp
39 self.content = content
40 self.uri = uri
41
43 """Calculate the reason for the error from the response content."""
44 reason = self.resp.reason
45 try:
46 data = json.loads(self.content)
47 reason = data['error']['message']
48 except (ValueError, KeyError):
49 pass
50 if reason is None:
51 reason = ''
52 return reason
53
55 if self.uri:
56 return '<HttpError %s when requesting %s returned "%s">' % (
57 self.resp.status, self.uri, self._get_reason().strip())
58 else:
59 return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
60
61 __str__ = __repr__
62
65 """The JSON returned could not be parsed."""
66 pass
67
70 """File type unknown or unexpected."""
71 pass
72
75 """Link type unknown or unexpected."""
76 pass
77
80 """No API with that name and version exists."""
81 pass
82
85 """That is an unacceptable mimetype for this operation."""
86 pass
87
92
95 """Error occured during resumable upload."""
96 pass
97
100 """The given chunksize is not valid."""
101 pass
102
104 """The channel Notification is invalid."""
105 pass
106
108 """Error occured during batch operations."""
109
110 @util.positional(2)
111 - def __init__(self, reason, resp=None, content=None):
112 self.resp = resp
113 self.content = content
114 self.reason = reason
115
117 return '<BatchError %s "%s">' % (self.resp.status, self.reason)
118
119 __str__ = __repr__
120
123 """Exception raised by RequestMockBuilder on unexpected calls."""
124
125 @util.positional(1)
127 """Constructor for an UnexpectedMethodError."""
128 super(UnexpectedMethodError, self).__init__(
129 'Received unexpected call %s' % methodId)
130
131
132 -class UnexpectedBodyError(Error):
133 """Exception raised by RequestMockBuilder on unexpected bodies."""
134
135 - def __init__(self, expected, provided):
136 """Constructor for an UnexpectedMethodError."""
137 super(UnexpectedBodyError, self).__init__(
138 'Expected: [%s] - Provided: [%s]' % (expected, provided))
139