68
76
"Response headers:\n---\n%s\n---\n"
69
77
"Response body:\n---\n%s\n---\n") % (
70
78
self.response.status, self.response.reason, headers, self.content)
81
class ClientError(HTTPError):
82
"""An exception representing a client-side error."""
85
class Unauthorized(ClientError):
86
"""An exception representing an authentication failure."""
89
class NotFound(ClientError):
90
"""An exception representing a nonexistent resource."""
93
class MethodNotAllowed(ClientError):
94
"""An exception raised when you use an unsupported HTTP method.
96
This is most likely because you tried to delete a resource that
101
class BadRequest(ClientError):
102
"""An exception representing a problem with a client request."""
105
class Conflict(ClientError):
106
"""An exception representing a conflict with another client."""
109
class PreconditionFailed(ClientError):
110
"""An exception representing the failure of a conditional PUT/PATCH.
112
The most likely explanation is that another client changed this
113
object while you were working on it, and your version of the
114
object is now out of date.
117
class ServerError(HTTPError):
118
"""An exception representing a server-side error."""
121
def error_for(response, content):
122
"""Turn an HTTP response into an HTTPError subclass.
124
:return: None if the response code is 1xx, 2xx or 3xx. Otherwise,
125
an instance of an appropriate HTTPError subclass (or HTTPError
126
if nothing else is appropriate.
128
http_errors_by_status_code = {
132
405 : MethodNotAllowed,
134
412 : PreconditionFailed,
137
if response.status // 100 <= 3:
138
# 1xx, 2xx and 3xx are not considered errors.
141
cls = http_errors_by_status_code.get(response.status, HTTPError)
143
if response.status // 100 == 5:
145
elif response.status // 100 == 4:
147
return cls(response, content)