From c5a66ee372ef824179a199b88dc41ba9755afa06 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Fri, 7 Mar 2025 14:17:15 -0800 Subject: [PATCH 1/2] refactor: Update error handling and API error mapping in errors.py - Add `UnauthorizedError` for handling unauthorized API actions - Replace `InvalidProjectError` with `InvalidModelIdError` - Modify `raise_api_error()` to handle more complex error response structures - Update error code mappings to match new API error conventions - Remove deprecated error classes and mappings --- validmind/errors.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/validmind/errors.py b/validmind/errors.py index a7db65c49..2dd19b104 100644 --- a/validmind/errors.py +++ b/validmind/errors.py @@ -42,6 +42,14 @@ class GetTestSuiteError(BaseError): pass +class UnauthorizedError(APIRequestError): + """ + When the user is not authorized to perform the API action. + """ + + pass + + class MissingCacheResultsArgumentsError(BaseError): """ When the cache_results function is missing arguments. @@ -81,19 +89,11 @@ class InvalidContentIdPrefixError(APIRequestError): """ -class InvalidMetricResultsError(APIRequestError): - """ - When an invalid metric results object is sent to the API. - """ - - pass - - -class InvalidProjectError(APIRequestError): +class InvalidModelIdError(APIRequestError): def description(self, *args, **kwargs): return ( self.message - or "Invalid project ID. Please ensure that you have provided a project ID that belongs to your organization." + or "Invalid model ID. Please ensure that you have provided a model ID that belongs to your organization." ) @@ -327,21 +327,23 @@ def raise_api_error(error_string): """ try: json_response = json.loads(error_string) - api_code = json_response.get("code") - api_description = json_response.get("description", json_response.get("message")) + error = json_response.get("error", {}) + error_details = error.get("details", {}) + error_reason = error_details.get("reason") + api_code = error.get("code") + api_description = error_reason or error.get("message") except json.decoder.JSONDecodeError: api_code = "unknown" api_description = error_string error_map = { - "invalid_credentials": InvalidAPICredentialsError, - "invalid_project": InvalidProjectError, - "invalid_json": InvalidRequestBodyError, - "missing_content_id": MissingTextContentIdError, + "INVALID_CREDENTIALS": InvalidAPICredentialsError, + "INVALID_MODEL": InvalidModelIdError, + "UNAUTHORIZED": UnauthorizedError, + "VALIDATION_ERROR": InvalidRequestBodyError, "missing_text": MissingTextContentsError, "invalid_text_object": InvalidTextObjectError, "invalid_content_id_prefix": InvalidContentIdPrefixError, - "invalid_metric_results": InvalidMetricResultsError, "invalid_test_results": InvalidTestResultsError, } From 25affcae9d5ea9a0c8bf80fd53b7a3a3e46eccaf Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Fri, 7 Mar 2025 14:17:23 -0800 Subject: [PATCH 2/2] 2.8.13 --- pyproject.toml | 2 +- validmind/__version__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e05f66c10..4ec821c4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ description = "ValidMind Library" license = "Commercial License" name = "validmind" readme = "README.pypi.md" -version = "2.8.12" +version = "2.8.13" [tool.poetry.dependencies] aiohttp = {extras = ["speedups"], version = "*"} diff --git a/validmind/__version__.py b/validmind/__version__.py index 7953a978c..76aba1042 100644 --- a/validmind/__version__.py +++ b/validmind/__version__.py @@ -1 +1 @@ -__version__ = "2.8.12" +__version__ = "2.8.13"