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 if self.resp.get('content-type', '').startswith('application/json'):
45 try:
46 data = simplejson.loads(self.content)
47 reason = data['error']['message']
48 except (ValueError, KeyError):
49 reason = self.content
50 else:
51 reason = self.resp.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())
58 else:
59 return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
60
61 __str__ = __repr__
62
63
65 """The JSON returned could not be parsed."""
66 pass
67
68
70 """Link type unknown or unexpected."""
71 pass
72
73
75 """No API with that name and version exists."""
76 pass
77
78
80 """That is an unacceptable mimetype for this operation."""
81 pass
82
83
87
88
90 """Error occured during resumable upload."""
91 pass
92
93
95 """Error occured during batch operations."""
96
97 - def __init__(self, reason, resp=None, content=None):
98 self.resp = resp
99 self.content = content
100 self.reason = reason
101
103 return '<BatchError %s "%s">' % (self.resp.status, self.reason)
104
105 __str__ = __repr__
106
107
109 """Exception raised by RequestMockBuilder on unexpected calls."""
110
112 """Constructor for an UnexpectedMethodError."""
113 super(UnexpectedMethodError, self).__init__(
114 'Received unexpected call %s' % methodId)
115
116
118 """Exception raised by RequestMockBuilder on unexpected bodies."""
119
120 - def __init__(self, expected, provided):
121 """Constructor for an UnexpectedMethodError."""
122 super(UnexpectedBodyError, self).__init__(
123 'Expected: [%s] - Provided: [%s]' % (expected, provided))
124