Fix usage of NotFound exception
All built-in inheritors of osc_lib.exceptions.ClientException expects 3 positional arguments: first argument is code, the second one is message. osc_lib.api.api.BaseAPI raises NotFound exception with transmitting only message arguments which goes to position of 'code' argument. This patch adds `code=404` argument and passes actual message as 'message'. Also, this patch adds a hack that processes code as message n case when code is not an integer and None was found at 'message' argument. Funny fact: More than 4 years ago, I proposed a similar fix to oslo-incubator... it was so long ago... https://review.opendev.org/#/c/94884 :) Change-Id: I022bbf3ce4bdd48b3bdcb008ee872c4f62a7b12b
This commit is contained in:
parent
e78db3b892
commit
2d4f3da090
@ -361,7 +361,7 @@ class BaseAPI(object):
|
|||||||
num_bulk = len(bulk_list)
|
num_bulk = len(bulk_list)
|
||||||
if num_bulk == 0:
|
if num_bulk == 0:
|
||||||
msg = _("none found")
|
msg = _("none found")
|
||||||
raise exceptions.NotFound(msg)
|
raise exceptions.NotFound(404, msg)
|
||||||
elif num_bulk > 1:
|
elif num_bulk > 1:
|
||||||
msg = _("many found")
|
msg = _("many found")
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
@ -388,7 +388,7 @@ class BaseAPI(object):
|
|||||||
|
|
||||||
def raise_not_found():
|
def raise_not_found():
|
||||||
msg = _("%s not found") % value
|
msg = _("%s not found") % value
|
||||||
raise exceptions.NotFound(msg)
|
raise exceptions.NotFound(404, msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = self._request(
|
ret = self._request(
|
||||||
|
@ -55,6 +55,9 @@ class ClientException(Exception):
|
|||||||
"""The base exception class for all exceptions this library raises."""
|
"""The base exception class for all exceptions this library raises."""
|
||||||
|
|
||||||
def __init__(self, code, message=None, details=None):
|
def __init__(self, code, message=None, details=None):
|
||||||
|
if not isinstance(code, int) and message is None:
|
||||||
|
message = code
|
||||||
|
code = self.http_status
|
||||||
self.code = code
|
self.code = code
|
||||||
self.message = message or self.__class__.message
|
self.message = message or self.__class__.message
|
||||||
self.details = details
|
self.details = details
|
||||||
|
Loading…
Reference in New Issue
Block a user