docs: Add exception documentation

Provide a list of available exceptions and stress that callers must
handle these themselves.

Change-Id: If3f56524a4642e0e147305758a8c5a4cc88c94bd
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2023-08-17 11:01:13 +01:00
parent 7349594757
commit d84495279d
3 changed files with 31 additions and 19 deletions

View File

@ -0,0 +1,15 @@
Exceptions
==========
openstacksdk provides a number of `exceptions`__ for commonly encountered
issues, such as missing API endpoints, various HTTP error codes, timeouts and
so forth. It is the responsibility of the calling application to handle these
exceptions appropriately.
Available exceptions
--------------------
.. automodule:: openstack.exceptions
:members:
.. __: https://docs.python.org/3/library/exceptions.html

View File

@ -171,6 +171,19 @@ can be customized.
resource resource
service_description service_description
utils utils
Errors and warnings
~~~~~~~~~~~~~~~~~~~
The SDK attempts to provide detailed errors and warnings for things like failed
requests, deprecated APIs, and invalid configurations. Application developers
are responsible for handling these errors and can opt into warnings to ensure
their applications stay up-to-date.
.. toctree::
:maxdepth: 1
exceptions
warnings warnings
Presentations Presentations

View File

@ -57,6 +57,8 @@ class InvalidRequest(SDKException):
class HttpException(SDKException, _rex.HTTPError): class HttpException(SDKException, _rex.HTTPError):
"""The base exception for all HTTP error responses."""
def __init__( def __init__(
self, self,
message='Error', message='Error',
@ -119,26 +121,18 @@ class HttpException(SDKException, _rex.HTTPError):
class BadRequestException(HttpException): class BadRequestException(HttpException):
"""HTTP 400 Bad Request.""" """HTTP 400 Bad Request."""
pass
class ForbiddenException(HttpException): class ForbiddenException(HttpException):
"""HTTP 403 Forbidden Request.""" """HTTP 403 Forbidden Request."""
pass
class ConflictException(HttpException): class ConflictException(HttpException):
"""HTTP 409 Conflict.""" """HTTP 409 Conflict."""
pass
class PreconditionFailedException(HttpException): class PreconditionFailedException(HttpException):
"""HTTP 412 Precondition Failed.""" """HTTP 412 Precondition Failed."""
pass
class MethodNotSupported(SDKException): class MethodNotSupported(SDKException):
"""The resource does not support this operation type.""" """The resource does not support this operation type."""
@ -161,13 +155,9 @@ class MethodNotSupported(SDKException):
class DuplicateResource(SDKException): class DuplicateResource(SDKException):
"""More than one resource exists with that name.""" """More than one resource exists with that name."""
pass
class ResourceNotFound(HttpException): class ResourceNotFound(HttpException):
"""No resource exists with that name or id.""" """No resource exists with that name or ID."""
pass
NotFoundException = ResourceNotFound NotFoundException = ResourceNotFound
@ -176,20 +166,14 @@ NotFoundException = ResourceNotFound
class ResourceTimeout(SDKException): class ResourceTimeout(SDKException):
"""Timeout waiting for resource.""" """Timeout waiting for resource."""
pass
class ResourceFailure(SDKException): class ResourceFailure(SDKException):
"""General resource failure.""" """General resource failure."""
pass
class InvalidResourceQuery(SDKException): class InvalidResourceQuery(SDKException):
"""Invalid query params for resource.""" """Invalid query params for resource."""
pass
def _extract_message(obj): def _extract_message(obj):
if isinstance(obj, dict): if isinstance(obj, dict):