Set default http-based exception as `HttpError`

Since exceptions from oslo is used, ClientException doesn't have any
attributes related to HTTP, so `HttpError` should be set as default
http-based exception.

Also, attribute `code` is used in several project, so it should be
returned and marked as deprecated.

Partial-Bug: #1322183
Change-Id: I3c71e2d25d6e36b5bac0f2b3add74d6747cf7c25
This commit is contained in:
Andrey Kurilin 2014-05-19 13:48:29 +03:00
parent 73dcda4fce
commit 4e1ee66108
2 changed files with 13 additions and 3 deletions

View File

@ -191,7 +191,7 @@ class ManagerWithFind(Manager):
num_matches = len(matches)
if num_matches == 0:
msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
raise exceptions.NotFound(404, msg)
raise exceptions.NotFound(msg)
elif num_matches > 1:
raise exceptions.NoUniqueMatch
else:

View File

@ -28,6 +28,15 @@ from novaclient.openstack.common.apiclient.exceptions import * # noqa
OverLimit = RequestEntityTooLarge
def _deprecate_code_attribute(slf):
import warnings
warnings.warn("'code' attribute is deprecated since v.2.17.0. Use "
"'http_status' instead of this one.", UserWarning)
return slf.http_status
HttpError.code = property(_deprecate_code_attribute)
class NoTokenLookupException(ClientException):
"""This form of authentication does not support looking up
endpoints from an existing token.
@ -57,7 +66,7 @@ _code_map = dict(
def from_response(response, body, url, method=None):
"""
Return an instance of an ClientException or subclass
Return an instance of an HttpError or subclass
based on an requests response.
Usage::
@ -91,5 +100,6 @@ def from_response(response, body, url, method=None):
kwargs['message'] = message
kwargs['details'] = details
cls = _code_map.get(response.status_code, ClientException)
cls = _code_map.get(response.status_code, HttpError)
return cls(**kwargs)