ClientExceptions should include url and method
Fixes Bug 1103557. novaclient abstracts out http request from user/client making it unknown to user what root cause behind nova client exceptions being raised. By including url and method in exception handling, this allows user to handle accordingly. Change-Id: I1a509bb932b3fd029bd0870ab699a39e21da19bb
This commit is contained in:
parent
5b8099cd0e
commit
0614ae75f6
novaclient
@ -192,7 +192,7 @@ class HTTPClient(object):
|
||||
body = None
|
||||
|
||||
if resp.status_code >= 400:
|
||||
raise exceptions.from_response(resp, body)
|
||||
raise exceptions.from_response(resp, body, url, method)
|
||||
|
||||
return resp, body
|
||||
|
||||
@ -275,7 +275,7 @@ class HTTPClient(object):
|
||||
elif resp.status_code == 305:
|
||||
return resp.headers['location']
|
||||
else:
|
||||
raise exceptions.from_response(resp, body)
|
||||
raise exceptions.from_response(resp, body, url)
|
||||
|
||||
def _fetch_endpoints_from_auth(self, url):
|
||||
"""We have a token, but don't know the final endpoint for
|
||||
@ -409,7 +409,7 @@ class HTTPClient(object):
|
||||
elif resp.status_code == 305:
|
||||
return resp.headers['location']
|
||||
else:
|
||||
raise exceptions.from_response(resp, body)
|
||||
raise exceptions.from_response(resp, body, url)
|
||||
|
||||
def _plugin_auth(self, auth_url):
|
||||
"""Load plugin-based authentication"""
|
||||
|
@ -66,11 +66,14 @@ class ClientException(Exception):
|
||||
"""
|
||||
The base exception class for all exceptions this library raises.
|
||||
"""
|
||||
def __init__(self, code, message=None, details=None, request_id=None):
|
||||
def __init__(self, code, message=None, details=None, request_id=None,
|
||||
url=None, method=None):
|
||||
self.code = code
|
||||
self.message = message or self.__class__.message
|
||||
self.details = details
|
||||
self.request_id = request_id
|
||||
self.url = url
|
||||
self.method = method
|
||||
|
||||
def __str__(self):
|
||||
formatted_string = "%s (HTTP %s)" % (self.message, self.code)
|
||||
@ -140,7 +143,7 @@ _code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized,
|
||||
Forbidden, NotFound, OverLimit, HTTPNotImplemented])
|
||||
|
||||
|
||||
def from_response(response, body):
|
||||
def from_response(response, body, url, method=None):
|
||||
"""
|
||||
Return an instance of an ClientException or subclass
|
||||
based on an requests response.
|
||||
@ -164,6 +167,7 @@ def from_response(response, body):
|
||||
message = error.get('message', None)
|
||||
details = error.get('details', None)
|
||||
return cls(code=response.status_code, message=message, details=details,
|
||||
request_id=request_id)
|
||||
request_id=request_id, url=url, method=method)
|
||||
else:
|
||||
return cls(code=response.status_code, request_id=request_id)
|
||||
return cls(code=response.status_code, request_id=request_id, url=url,
|
||||
method=method)
|
||||
|
Loading…
x
Reference in New Issue
Block a user