Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/google-endpoints/apitools/base/py/exceptions.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 Google Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """Exceptions for generated client libraries."""
18
19
20 class Error(Exception):
21
22 """Base class for all exceptions."""
23
24
25 class TypecheckError(Error, TypeError):
26
27 """An object of an incorrect type is provided."""
28
29
30 class NotFoundError(Error):
31
32 """A specified resource could not be found."""
33
34
35 class UserError(Error):
36
37 """Base class for errors related to user input."""
38
39
40 class InvalidDataError(Error):
41
42 """Base class for any invalid data error."""
43
44
45 class CommunicationError(Error):
46
47 """Any communication error talking to an API server."""
48
49
50 class HttpError(CommunicationError):
51
52 """Error making a request. Soon to be HttpError."""
53
54 def __init__(self, response, content, url):
55 super(HttpError, self).__init__()
56 self.response = response
57 self.content = content
58 self.url = url
59
60 def __str__(self):
61 content = self.content.decode('ascii', 'replace')
62 return 'HttpError accessing <%s>: response: <%s>, content <%s>' % (
63 self.url, self.response, content)
64
65 @property
66 def status_code(self):
67 # TODO(craigcitro): Turn this into something better than a
68 # KeyError if there is no status.
69 return int(self.response['status'])
70
71 @classmethod
72 def FromResponse(cls, http_response):
73 return cls(http_response.info, http_response.content,
74 http_response.request_url)
75
76
77 class InvalidUserInputError(InvalidDataError):
78
79 """User-provided input is invalid."""
80
81
82 class InvalidDataFromServerError(InvalidDataError, CommunicationError):
83
84 """Data received from the server is malformed."""
85
86
87 class BatchError(Error):
88
89 """Error generated while constructing a batch request."""
90
91
92 class ConfigurationError(Error):
93
94 """Base class for configuration errors."""
95
96
97 class GeneratedClientError(Error):
98
99 """The generated client configuration is invalid."""
100
101
102 class ConfigurationValueError(UserError):
103
104 """Some part of the user-specified client configuration is invalid."""
105
106
107 class ResourceUnavailableError(Error):
108
109 """User requested an unavailable resource."""
110
111
112 class CredentialsError(Error):
113
114 """Errors related to invalid credentials."""
115
116
117 class TransferError(CommunicationError):
118
119 """Errors related to transfers."""
120
121
122 class TransferRetryError(TransferError):
123
124 """Retryable errors related to transfers."""
125
126
127 class TransferInvalidError(TransferError):
128
129 """The given transfer is invalid."""
130
131
132 class RequestError(CommunicationError):
133
134 """The request was not successful."""
135
136
137 class RetryAfterError(HttpError):
138
139 """The response contained a retry-after header."""
140
141 def __init__(self, response, content, url, retry_after):
142 super(RetryAfterError, self).__init__(response, content, url)
143 self.retry_after = int(retry_after)
144
145 @classmethod
146 def FromResponse(cls, http_response):
147 return cls(http_response.info, http_response.content,
148 http_response.request_url, http_response.retry_after)
149
150
151 class BadStatusCodeError(HttpError):
152
153 """The request completed but returned a bad status code."""
154
155
156 class NotYetImplementedError(GeneratedClientError):
157
158 """This functionality is not yet implemented."""
159
160
161 class StreamExhausted(Error):
162
163 """Attempted to read more bytes from a stream than were available."""
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698