diff --git a/meilisearch/client.py b/meilisearch/client.py index 3f289bf8..2de34bc6 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -72,7 +72,7 @@ def delete_index_if_exists(self, uid: str) -> bool: self.http.delete(f'{self.config.paths.index}/{uid}') return True except MeiliSearchApiError as error: - if error.error_code != "index_not_found": + if error.code != "index_not_found": raise error return False @@ -200,7 +200,7 @@ def get_or_create_index(self, uid: str, options: Optional[Dict[str, Any]] = None try: index_instance = self.get_index(uid) except MeiliSearchApiError as err: - if err.error_code != 'index_not_found': + if err.code != 'index_not_found': raise err index_instance = self.create_index(uid, options) return index_instance diff --git a/meilisearch/errors.py b/meilisearch/errors.py index 51891b56..2c031196 100644 --- a/meilisearch/errors.py +++ b/meilisearch/errors.py @@ -17,21 +17,21 @@ class MeiliSearchApiError(MeiliSearchError): def __init__(self, error: str, request: Response) -> None: self.status_code = request.status_code - self.error_code = None - self.error_link = None + self.code = None + self.link = None if request.text: json_data = json.loads(request.text) self.message = json_data.get('message') - self.error_code = json_data.get('errorCode') - self.error_link = json_data.get('errorLink') + self.code = json_data.get('code') + self.link = json_data.get('link') else: self.message = error super().__init__(self.message) def __str__(self) -> str: - if self.error_code and self.error_link: - return f'MeiliSearchApiError. Error code: {self.error_code}. Error message: {self.message}. Error documentation: {self.error_link}' + if self.code and self.link: + return f'MeiliSearchApiError. Error code: {self.code}. Error message: {self.message}. Error documentation: {self.link}' return f'MeiliSearchApiError. {self.message}' diff --git a/meilisearch/index.py b/meilisearch/index.py index 97157b99..d6465421 100644 --- a/meilisearch/index.py +++ b/meilisearch/index.py @@ -70,7 +70,7 @@ def delete_if_exists(self) -> bool: self.delete() return True except MeiliSearchApiError as error: - if error.error_code != "index_not_found": + if error.code != "index_not_found": raise error return False diff --git a/meilisearch/tests/errors/test_api_error_meilisearch.py b/meilisearch/tests/errors/test_api_error_meilisearch.py index 8a75e58e..da3f7947 100644 --- a/meilisearch/tests/errors/test_api_error_meilisearch.py +++ b/meilisearch/tests/errors/test_api_error_meilisearch.py @@ -18,7 +18,7 @@ def test_meilisearch_api_error_wrong_master_key(): client.create_index("some_index") @patch('requests.post') -def test_meilisearch_api_error_no_error_code(mock_post): +def test_meilisearch_api_error_no_code(mock_post): """Here to test for regressions related to https://github.com/meilisearch/meilisearch-python/issues/305.""" mock_response = requests.models.Response()