Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 3.38 KB

exceptions.rst

File metadata and controls

49 lines (35 loc) · 3.38 KB

Exception handling

When using the Python SDK, you should be prepared to handle the following exceptions:

Handling HTTP 3xx responses

As a result of the SDK treating responses with a non-2xx HTTP status as a :py:class:`~oci.exceptions.ServiceError` the SDK will throw a :py:class:`~oci.exceptions.ServiceError` on 3xx responses. This can impact operations which support conditional GETs, such as :py:meth:`~oci.object_storage.object_storage_client.ObjectStorageClient.get_object` and :py:meth:`~oci.object_storage.object_storage_client.ObjectStorageClient.head_object` methods as these can return responses with a HTTP status code of 304 if passed an if_none_match which corresponds to the curent etag of the object or bucket.

In order to account for this, you should catch :py:class:`~oci.exceptions.ServiceError` and check its status attribute for the HTTP status code. For example:

import oci

config = oci.config.from_file()
client = oci.object_storage.ObjectStorageClient(config)

try:
    get_object_response = client.get_object('my_namespace', 'my_bucket', 'my_object', if_none_match='some_etag_value')
except oci.exceptions.ServiceError as e:
    if e.status == 304:
        # Object exists but has not been modified (based on the etag value)
        pass
    else:
        raise