From 1f44aff399e9ed6008d96b047a7c82623b980e0a Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Sun, 29 Jul 2012 23:08:02 -0700 Subject: [PATCH] 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 --- glanceclient/exc.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/glanceclient/exc.py b/glanceclient/exc.py index 487dd74..bcedbd2 100644 --- a/glanceclient/exc.py +++ b/glanceclient/exc.py @@ -90,6 +90,14 @@ class OverLimit(ClientException): message = "Over limit" +class InternalServerError(ClientException): + """ + HTTP 500 - Internal Server Error + """ + http_status = 500 + message = "Internal Server Error" + + # NotImplemented is a python keyword. class HTTPNotImplemented(ClientException): """ @@ -99,14 +107,23 @@ class HTTPNotImplemented(ClientException): 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__() # so we can do this: # _code_map = dict((c.http_status, c) # for c in ClientException.__subclasses__()) # # Instead, we have to hardcode it: -_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized, - Forbidden, NotFound, OverLimit, HTTPNotImplemented]) +_exc_list = [BadRequest, Unauthorized, Forbidden, NotFound, OverLimit, + InternalServerError, HTTPNotImplemented, ServiceUnavailable] +_code_map = dict((c.http_status, c) for c in _exc_list) def from_response(response):