forked from loafle/openapi-generator-original
[python-experimental] Raise builtin AttributeError instead of custom ApiKeyError (#6229)
* Use AttributeError instead of ApiKeyError because that's what the hasattr builtin function uses * Use AttributeError instead of ApiKeyError because that's what the hasattr builtin function uses * fix unit tests * create ApiAttributeError exception * fix formatting * run samples scripts
This commit is contained in:
@@ -31,6 +31,7 @@ from petstore_api.exceptions import OpenApiException
|
||||
from petstore_api.exceptions import ApiTypeError
|
||||
from petstore_api.exceptions import ApiValueError
|
||||
from petstore_api.exceptions import ApiKeyError
|
||||
from petstore_api.exceptions import ApiAttributeError
|
||||
from petstore_api.exceptions import ApiException
|
||||
# import models into sdk package
|
||||
from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType
|
||||
|
||||
@@ -64,6 +64,25 @@ class ApiValueError(OpenApiException, ValueError):
|
||||
super(ApiValueError, self).__init__(full_msg)
|
||||
|
||||
|
||||
class ApiAttributeError(OpenApiException, AttributeError):
|
||||
def __init__(self, msg, path_to_item=None):
|
||||
"""
|
||||
Raised when an attribute reference or assignment fails.
|
||||
|
||||
Args:
|
||||
msg (str): the exception message
|
||||
|
||||
Keyword Args:
|
||||
path_to_item (None/list) the path to the exception in the
|
||||
received_data dict
|
||||
"""
|
||||
self.path_to_item = path_to_item
|
||||
full_msg = msg
|
||||
if path_to_item:
|
||||
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||
super(ApiAttributeError, self).__init__(full_msg)
|
||||
|
||||
|
||||
class ApiKeyError(OpenApiException, KeyError):
|
||||
def __init__(self, msg, path_to_item=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user