1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Errors for the library.
18
19 All exceptions defined by the library
20 should be defined in this file.
21 """
22
23 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
24
25
26 from oauth2client.anyjson import simplejson
27
28
30 """Base error for this module."""
31 pass
32
33
35 """HTTP data was invalid or unexpected."""
36
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 = simplejson.loads(self.content)
47 reason = data['error']['message']
48 except (ValueError, KeyError):
49 pass
50 return reason
51
53 if self.uri:
54 return '<HttpError %s when requesting %s returned "%s">' % (
55 self.resp.status, self.uri, self._get_reason().strip())
56 else:
57 return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
58
59 __str__ = __repr__
60
61
63 """The JSON returned could not be parsed."""
64 pass
65
66
68 """Link type unknown or unexpected."""
69 pass
70
71
73 """No API with that name and version exists."""
74 pass
75
76
78 """That is an unacceptable mimetype for this operation."""
79 pass
80
81
85
86
88 """Error occured during resumable upload."""
89 pass
90
91
93 """Error occured during batch operations."""
94
95 - def __init__(self, reason, resp=None, content=None):
96 self.resp = resp
97 self.content = content
98 self.reason = reason
99
101 return '<BatchError %s "%s">' % (self.resp.status, self.reason)
102
103 __str__ = __repr__
104
105
107 """Exception raised by RequestMockBuilder on unexpected calls."""
108
110 """Constructor for an UnexpectedMethodError."""
111 super(UnexpectedMethodError, self).__init__(
112 'Received unexpected call %s' % methodId)
113
114
116 """Exception raised by RequestMockBuilder on unexpected bodies."""
117
118 - def __init__(self, expected, provided):
119 """Constructor for an UnexpectedMethodError."""
120 super(UnexpectedBodyError, self).__init__(
121 'Expected: [%s] - Provided: [%s]' % (expected, provided))
122