8000 Improve exception handling: Properly raise `IntegrityError` exceptions · crate/crate-python@8c39426 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c39426

Browse files
committed
Improve exception handling: Properly raise IntegrityError exceptions
... when receiving `DuplicateKeyException` errors from CrateDB.
1 parent c276159 commit 8c39426

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/crate/client/http.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
BlobLocationNotFoundException,
5757
DigestNotFoundException,
5858
ProgrammingError,
59+
IntegrityError,
5960
)
6061

6162

@@ -191,6 +192,18 @@ def _ex_to_message(ex):
191192

192193

193194
def _raise_for_status(response):
195+
"""
196+
Properly raise `IntegrityError` exceptions for CrateDB's `DuplicateKeyException` errors.
197+
"""
198+
try:
199+
return _raise_for_status_real(response)
200+
except ProgrammingError as ex:
201+
if "DuplicateKeyException" in ex.message:
202+
raise IntegrityError(ex.message, error_trace=ex.error_trace) from ex
203+
raise
204+
205+
206+
def _raise_for_status_real(response):
194207
""" make sure that only crate.exceptions are raised that are defined in
195208
the DB-API specification """
196209
message = ''

0 commit comments

Comments
 (0)
0