Skip to content

Changes related to the next MeiliSearch release (v0.24.0) #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 16, 2021
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ index.search(

## 🤖 Compatibility with MeiliSearch

This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).
This package only guarantees the compatibility with the [version v0.24.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0).

## 💡 Learn More

Expand Down
4 changes: 2 additions & 2 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions meilisearch/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

Expand Down
2 changes: 1 addition & 1 deletion meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion meilisearch/tests/errors/test_api_error_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down