From d7a0592e28b7bc0e2821425d56903a046f3819dc Mon Sep 17 00:00:00 2001 From: Jared Casey Date: Thu, 14 May 2026 15:45:44 -0600 Subject: [PATCH 1/2] PYCO-98: Update Error Handling Changes ------- * Raise `AnalyticsError` if SDK receives HTTP 500 status code * Raise `AnalyticsError` if `start_query()` response is missing `requestID` or `handle` --- acouchbase_analytics/protocol/query_handle.py | 14 ++++++++++---- couchbase_analytics/protocol/errors.py | 2 ++ couchbase_analytics/protocol/query_handle.py | 14 ++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/acouchbase_analytics/protocol/query_handle.py b/acouchbase_analytics/protocol/query_handle.py index 9a31803..d8fb81d 100644 --- a/acouchbase_analytics/protocol/query_handle.py +++ b/acouchbase_analytics/protocol/query_handle.py @@ -23,7 +23,7 @@ from acouchbase_analytics.protocol._core.response import AsyncHttpResponse from acouchbase_analytics.protocol.streaming import AsyncHttpStreamingResponse from couchbase_analytics.common._core.query_handle import QueryHandleStatusResponse -from couchbase_analytics.common.errors import AnalyticsError, QueryNotFoundError +from couchbase_analytics.common.errors import AnalyticsError from couchbase_analytics.common.query_handle import AsyncQueryHandle as _CoreAsyncQueryHandle from couchbase_analytics.common.query_handle import AsyncQueryResultHandle as _CoreAsyncQueryResultHandle from couchbase_analytics.common.query_handle import AsyncQueryStatus as _CoreAsyncQueryStatus @@ -79,11 +79,17 @@ def _get_status_handle(self) -> None: raise AnalyticsError(message='HTTP response does not contain JSON data.') request_id = self._http_response.json_response.get('requestID', None) - if request_id is None: - raise QueryNotFoundError(message='Server response is missing "requestID" field.') handle = self._http_response.json_response.get('handle', None) + required_fields_missing = [] + if request_id is None: + required_fields_missing.append('requestID') + if handle is None: - raise QueryNotFoundError(message='Server response is missing "handle" field.') + required_fields_missing.append('handle') + + if len(required_fields_missing) > 0: + msg = f'Server response is missing required field(s): {", ".join(required_fields_missing)}.' + raise AnalyticsError(message=msg) self._request_id = request_id self._handle = handle diff --git a/couchbase_analytics/protocol/errors.py b/couchbase_analytics/protocol/errors.py index 5f2ea97..8d63a6c 100644 --- a/couchbase_analytics/protocol/errors.py +++ b/couchbase_analytics/protocol/errors.py @@ -170,6 +170,8 @@ def maybe_get_error_from_status_code( err = WrappedError(InvalidCredentialError(context=context, message='Invalid credentials provided.')) elif status_code == 404 and ignore_not_found_status is not True: err = WrappedError(QueryNotFoundError(context=context, message='Resource not found')) + elif status_code == 500: + err = WrappedError(AnalyticsError(context=context, message='Server error.')) elif status_code == 503: err = WrappedError(AnalyticsError(context=context, message='Service unavailable.'), retriable=True) diff --git a/couchbase_analytics/protocol/query_handle.py b/couchbase_analytics/protocol/query_handle.py index a37d5ca..3a63bc4 100644 --- a/couchbase_analytics/protocol/query_handle.py +++ b/couchbase_analytics/protocol/query_handle.py @@ -20,7 +20,7 @@ from typing import TYPE_CHECKING, Any, Optional from couchbase_analytics.common._core.query_handle import QueryHandleStatusResponse -from couchbase_analytics.common.errors import AnalyticsError, QueryNotFoundError +from couchbase_analytics.common.errors import AnalyticsError from couchbase_analytics.common.query_handle import BlockingQueryHandle as _CoreBlockingQueryHandle from couchbase_analytics.common.query_handle import BlockingQueryResultHandle as _CoreBlockingQueryResultHandle from couchbase_analytics.common.query_handle import BlockingQueryStatus as _CoreBlockingQueryStatus @@ -83,11 +83,17 @@ def _get_status_handle(self) -> None: raise AnalyticsError(message='HTTP response does not contain JSON data.') request_id = self._http_response.json_response.get('requestID', None) - if request_id is None: - raise QueryNotFoundError(message='Server response is missing "requestID" field.') handle = self._http_response.json_response.get('handle', None) + required_fields_missing = [] + if request_id is None: + required_fields_missing.append('requestID') + if handle is None: - raise QueryNotFoundError(message='Server response is missing "handle" field.') + required_fields_missing.append('handle') + + if len(required_fields_missing) > 0: + msg = f'Server response is missing required field(s): {", ".join(required_fields_missing)}.' + raise AnalyticsError(message=msg) self._request_id = request_id self._handle = handle From 5d11b7e25c401898e7aeee1a9f830617c4aa974a Mon Sep 17 00:00:00 2001 From: Jared Casey Date: Thu, 14 May 2026 18:46:16 -0600 Subject: [PATCH 2/2] Update AnalyticsError message Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- couchbase_analytics/protocol/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchbase_analytics/protocol/errors.py b/couchbase_analytics/protocol/errors.py index 8d63a6c..64a23ca 100644 --- a/couchbase_analytics/protocol/errors.py +++ b/couchbase_analytics/protocol/errors.py @@ -171,7 +171,7 @@ def maybe_get_error_from_status_code( elif status_code == 404 and ignore_not_found_status is not True: err = WrappedError(QueryNotFoundError(context=context, message='Resource not found')) elif status_code == 500: - err = WrappedError(AnalyticsError(context=context, message='Server error.')) + err = WrappedError(AnalyticsError(context=context, message='Internal server error (HTTP 500).')) elif status_code == 503: err = WrappedError(AnalyticsError(context=context, message='Service unavailable.'), retriable=True)