Add exceptions for 500 and 503 HTTP status codes
Add glance.exc.InternalServerError and .ServiceUnavailable to represent HTTP statuses 500 and 503. Users will definitely see these from Glance, so let's be nice and map them to handy exception classes. Change-Id: I8e8fcda532455793ea4d0f08a23f7c92b68c186c
This commit is contained in:
+19
-2
@@ -90,6 +90,14 @@ class OverLimit(ClientException):
|
|||||||
message = "Over limit"
|
message = "Over limit"
|
||||||
|
|
||||||
|
|
||||||
|
class InternalServerError(ClientException):
|
||||||
|
"""
|
||||||
|
HTTP 500 - Internal Server Error
|
||||||
|
"""
|
||||||
|
http_status = 500
|
||||||
|
message = "Internal Server Error"
|
||||||
|
|
||||||
|
|
||||||
# NotImplemented is a python keyword.
|
# NotImplemented is a python keyword.
|
||||||
class HTTPNotImplemented(ClientException):
|
class HTTPNotImplemented(ClientException):
|
||||||
"""
|
"""
|
||||||
@@ -99,14 +107,23 @@ class HTTPNotImplemented(ClientException):
|
|||||||
message = "Not Implemented"
|
message = "Not Implemented"
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceUnavailable(ClientException):
|
||||||
|
"""
|
||||||
|
HTTP 503 - Service Unavailable
|
||||||
|
"""
|
||||||
|
http_status = 503
|
||||||
|
message = "Service Unavailable"
|
||||||
|
|
||||||
|
|
||||||
# In Python 2.4 Exception is old-style and thus doesn't have a __subclasses__()
|
# In Python 2.4 Exception is old-style and thus doesn't have a __subclasses__()
|
||||||
# so we can do this:
|
# so we can do this:
|
||||||
# _code_map = dict((c.http_status, c)
|
# _code_map = dict((c.http_status, c)
|
||||||
# for c in ClientException.__subclasses__())
|
# for c in ClientException.__subclasses__())
|
||||||
#
|
#
|
||||||
# Instead, we have to hardcode it:
|
# Instead, we have to hardcode it:
|
||||||
_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized,
|
_exc_list = [BadRequest, Unauthorized, Forbidden, NotFound, OverLimit,
|
||||||
Forbidden, NotFound, OverLimit, HTTPNotImplemented])
|
InternalServerError, HTTPNotImplemented, ServiceUnavailable]
|
||||||
|
_code_map = dict((c.http_status, c) for c in _exc_list)
|
||||||
|
|
||||||
|
|
||||||
def from_response(response):
|
def from_response(response):
|
||||||
|
|||||||
Reference in New Issue
Block a user