Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"}
Expand Down
2 changes: 1 addition & 1 deletion validmind/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.8.12"
__version__ = "2.8.13"
36 changes: 19 additions & 17 deletions validmind/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."
)


Expand Down Expand Up @@ -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,
}

Expand Down
Loading