Custom exceptions
I think we should consider own error (exception) classes. There should be one base class named e.g. OnapSdkError. It can be used for example to handle API errors or invalid API return data syntax. Currently the most used solution is to use send_message
method exception
parameter
self.send_message(
"PUT",
"add tenant to cloud region",
f"{self.url}/tenants/tenant/{tenant_id}",
data=jinja_env()
.get_template("cloud_region_add_tenant.json.j2")
.render(tenant_id=tenant_id, tenant_name=tenant_name, tenant_context=tenant_context),
exception=ValueError
)
but it's difficult to separate if data has invalid syntax or API request returns error code. With custom exceptions it won't be needed, there can be just flag if user wants to raise an exception for error or not. It can be also easier for users to wrap code to catch base error instead of many different exception types, instead of:
try:
service.add_vnf(...)
except (AttributeError, ValueError):
log.error(...)
we can use
try:
service.add_vnf(...)
except OnapSdkError:
log.error(...)
I suggest to do it similar to requests library exceptions What do you think?
Edited by Eli Halych