Merge "docs: Add exception documentation"

This commit is contained in:
Zuul 2023-08-29 10:48:02 +00:00 committed by Gerrit Code Review
commit 9b49ddbb48
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
service_description
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
Presentations

View File

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