Add MethodNotAllowed and Conflict exception classes

It is expected to recieve a 405 or a 409 from Nova, but novaclient presents
them as a generic ClientException. This patch adds MethodNotAllowed
and Conflict classes to represent these HTTP responses.

Change-Id: If89cee04ebd74daaa28ea30b5c57cdc63edc1551
This commit is contained in:
Brian Waldon 2013-05-26 08:14:30 -07:00
parent 1a0b7b0a64
commit f2559c4c39
1 changed files with 19 additions and 2 deletions

View File

@ -116,6 +116,22 @@ class NotFound(ClientException):
message = "Not found"
class MethodNotAllowed(ClientException):
"""
HTTP 405 - Method Not Allowed
"""
http_status = 405
message = "Method Not Allowed"
class Conflict(ClientException):
"""
HTTP 409 - Conflict
"""
http_status = 409
message = "Conflict"
class OverLimit(ClientException):
"""
HTTP 413 - Over limit: you're over the API limits for this time period.
@ -147,8 +163,9 @@ class HTTPNotImplemented(ClientException):
# 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])
_error_classes = [BadRequest, Unauthorized, Forbidden, NotFound,
MethodNotAllowed, Conflict, OverLimit, HTTPNotImplemented]
_code_map = dict((c.http_status, c) for c in _error_classes)
def from_response(response, body, url, method=None):