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