From 34f758f183bb90e8516a234b0bc5033de6c2425d Mon Sep 17 00:00:00 2001 From: Karl Czajkowski Date: Mon, 26 Aug 2024 15:58:52 -0700 Subject: [PATCH] wrap some datapath insert/update HTTP exceptions in datapath-specific exception For compatibility with existing clients, continue to wrap the same HTTP error code range in a datapath exception --- deriva/core/datapath.py | 48 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/deriva/core/datapath.py b/deriva/core/datapath.py index 126ff16..721838c 100644 --- a/deriva/core/datapath.py +++ b/deriva/core/datapath.py @@ -1016,16 +1016,23 @@ def results_func(ignore1, ignore2, ignore3): max_batch_rows=max_batch_rows, max_batch_bytes=max_batch_bytes ): - if retry_safe: - resp = _request_with_retry( - lambda: request_func(batch), - retry_codes=retry_codes, - backoff_factor=backoff_factor, - max_attempts=max_attempts - ) - else: - resp = request_func(batch) - results.extend(resp.json()) + try: + if retry_safe: + resp = _request_with_retry( + lambda: request_func(batch), + retry_codes=retry_codes, + backoff_factor=backoff_factor, + max_attempts=max_attempts + ) + else: + resp = request_func(batch) + results.extend(resp.json()) + except HTTPError as e: + logger.debug(e.response.text) + if 400 <= e.response.status_code < 500: + raise DataPathException(_http_error_message(e), e) + else: + raise e return results result = _ResultSet(self.path.uri, results_func) @@ -1102,13 +1109,20 @@ def results_func(ignore1, ignore2, ignore3): max_batch_rows=max_batch_rows, max_batch_bytes=max_batch_bytes ): - resp = _request_with_retry( - lambda: request_func(batch), - retry_codes=retry_codes, - backoff_factor=backoff_factor, - max_attempts=max_attempts - ) - results.extend(resp.json()) + try: + resp = _request_with_retry( + lambda: request_func(batch), + retry_codes=retry_codes, + backoff_factor=backoff_factor, + max_attempts=max_attempts + ) + results.extend(resp.json()) + except HTTPError as e: + logger.debug(e.response.text) + if 400 <= e.response.status_code < 500: + raise DataPathException(_http_error_message(e), e) + else: + raise e return results result = _ResultSet(self.path.uri, results_func)