opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
338 stars 170 forks source link

Add semantic exception for when REST status == 400 with 'resource_already_exists_exception' #768

Open rbpasker opened 3 months ago

rbpasker commented 3 months ago
          its actually worse because there's no semantic error checking, eg

*** Error: RequestError(400, 'resource_already_exists_exception', 'index [opinions/FduukSQQQcuRcp4ZK0w51g] already exists') requires:

except TransportError as e:
    if e.status_code == 400 and e.error == 'resource_already_exists_exception':
        # Handle the specific exception
        print("Resource already exists.")
    else:
        # Handle other TransportError exceptions
        print(f"TransportError occurred: {e}")

so i have to write a helper that converts exceptions to semantic errors:

except TransportError as e:
     return transform_exception_to_return_value(e)

https://opensearch-project.github.io/opensearch-py/api-ref/exceptions.html#opensearchpy.TransportError

Originally posted by @rbpasker in https://github.com/opensearch-project/opensearch-py/issues/718#issuecomment-2189406536