Skip to content

Commit

Permalink
Update code base related to error changes (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza authored Oct 30, 2021
1 parent eb84ded commit 1b6f674
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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

0 comments on commit 1b6f674

Please sign in to comment.