Skip to content

Commit

Permalink
Improve exception handling: Properly raise IntegrityError exceptions
Browse files Browse the repository at this point in the history
... when receiving `DuplicateKeyException` errors from CrateDB.
  • Loading branch information
amotl committed Sep 28, 2023
1 parent c276159 commit 8c39426
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/crate/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
BlobLocationNotFoundException,
DigestNotFoundException,
ProgrammingError,
IntegrityError,
)


Expand Down Expand Up @@ -191,6 +192,18 @@ def _ex_to_message(ex):


def _raise_for_status(response):
"""
Properly raise `IntegrityError` exceptions for CrateDB's `DuplicateKeyException` errors.
"""
try:
return _raise_for_status_real(response)
except ProgrammingError as ex:
if "DuplicateKeyException" in ex.message:
raise IntegrityError(ex.message, error_trace=ex.error_trace) from ex

Check warning on line 202 in src/crate/client/http.py

View check run for this annotation

Codecov / codecov/patch

src/crate/client/http.py#L202

Added line #L202 was not covered by tests
raise


def _raise_for_status_real(response):
""" make sure that only crate.exceptions are raised that are defined in
the DB-API specification """
message = ''
Expand Down

0 comments on commit 8c39426

Please sign in to comment.