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..64a23ca 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='Internal server error (HTTP 500).')) 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