Skip to content

Change error names from MeiliSerach to Meilisearch #720

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 1 commit into from
Mar 23, 2023
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
12 changes: 6 additions & 6 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from meilisearch.config import Config
from meilisearch.errors import (
MeiliSearchApiError,
MeiliSearchCommunicationError,
MeiliSearchTimeoutError,
MeilisearchApiError,
MeilisearchCommunicationError,
MeilisearchTimeoutError,
)
from meilisearch.version import qualified_version

Expand Down Expand Up @@ -50,9 +50,9 @@ def send_request(
return self.__validate(request)

except requests.exceptions.Timeout as err:
raise MeiliSearchTimeoutError(str(err)) from err
raise MeilisearchTimeoutError(str(err)) from err
except requests.exceptions.ConnectionError as err:
raise MeiliSearchCommunicationError(str(err)) from err
raise MeilisearchCommunicationError(str(err)) from err

def get(self, path: str) -> Any:
return self.send_request(requests.get, path)
Expand Down Expand Up @@ -100,4 +100,4 @@ def __validate(request: requests.Response) -> Any:
request.raise_for_status()
return HttpRequests.__to_json(request)
except requests.exceptions.HTTPError as err:
raise MeiliSearchApiError(str(err), request) from err
raise MeilisearchApiError(str(err), request) from err
50 changes: 25 additions & 25 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from meilisearch._httprequests import HttpRequests
from meilisearch.config import Config
from meilisearch.errors import MeiliSearchError
from meilisearch.errors import MeilisearchError
from meilisearch.index import Index
from meilisearch.models.key import Key, KeysResults
from meilisearch.models.task import TaskInfo
Expand Down Expand Up @@ -61,7 +61,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Ta

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return Index.create(self.config, uid, options)
Expand All @@ -82,7 +82,7 @@ def delete_index(self, uid: str) -> TaskInfo:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""

Expand All @@ -105,7 +105,7 @@ def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str,

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
if parameters is None:
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_raw_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> List[D

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
if parameters is None:
Expand All @@ -161,7 +161,7 @@ def get_index(self, uid: str) -> Index:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return Index(self.config, uid).fetch_info()
Expand All @@ -182,7 +182,7 @@ def get_raw_index(self, uid: str) -> Dict[str, Any]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.get(f"{self.config.paths.index}/{uid}")
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_all_stats(self) -> Dict[str, Any]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.get(self.config.paths.stat)
Expand All @@ -233,7 +233,7 @@ def health(self) -> Dict[str, str]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.get(self.config.paths.health)
Expand All @@ -242,7 +242,7 @@ def is_healthy(self) -> bool:
"""Get health of the Meilisearch server."""
try:
self.health()
except MeiliSearchError:
except MeilisearchError:
return False
return True

Expand All @@ -262,7 +262,7 @@ def get_key(self, key_or_uid: str) -> Key:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
key = self.http.get(f"{self.config.paths.keys}/{key_or_uid}")
Expand All @@ -285,7 +285,7 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> KeysResults:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
if parameters is None:
Expand Down Expand Up @@ -314,7 +314,7 @@ def create_key(self, options: Dict[str, Any]) -> Key:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
task = self.http.post(f"{self.config.paths.keys}", options)
Expand All @@ -340,7 +340,7 @@ def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Key:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
url = f"{self.config.paths.keys}/{key_or_uid}"
Expand All @@ -364,7 +364,7 @@ def delete_key(self, key_or_uid: str) -> int:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
response = self.http.delete(f"{self.config.paths.keys}/{key_or_uid}")
Expand All @@ -381,7 +381,7 @@ def get_version(self) -> Dict[str, str]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.get(self.config.paths.version)
Expand All @@ -396,7 +396,7 @@ def version(self) -> Dict[str, str]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.get_version()
Expand All @@ -412,7 +412,7 @@ def create_dump(self) -> TaskInfo:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
task = self.http.post(self.config.paths.dumps)
Expand All @@ -435,7 +435,7 @@ def swap_indexes(self, parameters: List[Dict[str, List[str]]]) -> TaskInfo:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return TaskInfo(**self.http.post(self.config.paths.swap, parameters))
Expand All @@ -457,7 +457,7 @@ def get_tasks(

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.task_handler.get_tasks(parameters=parameters)
Expand All @@ -477,7 +477,7 @@ def get_task(self, uid: int) -> Dict[str, Any]:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.task_handler.get_task(uid)
Expand All @@ -498,7 +498,7 @@ def cancel_tasks(self, parameters: Dict[str, Any]) -> TaskInfo:

Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.task_handler.cancel_tasks(parameters=parameters)
Expand All @@ -517,7 +517,7 @@ def delete_tasks(self, parameters: Dict[str, Any]) -> TaskInfo:
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
Raises
------
MeiliSearchApiError
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.task_handler.delete_tasks(parameters=parameters)
Expand All @@ -535,7 +535,7 @@ def wait_for_task(
uid:
Identifier of the task to wait for being processed.
timeout_in_ms (optional):
Time the method should wait before raising a MeiliSearchTimeoutError
Time the method should wait before raising a MeilisearchTimeoutError
interval_in_ms (optional):
Time interval the method should wait (sleep) between requests

Expand All @@ -546,7 +546,7 @@ def wait_for_task(

Raises
------
MeiliSearchTimeoutError
MeilisearchTimeoutError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.task_handler.wait_for_task(uid, timeout_in_ms, interval_in_ms)
Expand Down
18 changes: 9 additions & 9 deletions meilisearch/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from requests import Response


class MeiliSearchError(Exception):
class MeilisearchError(Exception):
"""Generic class for Meilisearch error handling"""

def __init__(self, message: str) -> None:
self.message = message
super().__init__(self.message)

def __str__(self) -> str:
return f"MeiliSearchError. Error message: {self.message}"
return f"MeilisearchError. Error message: {self.message}"


class MeiliSearchApiError(MeiliSearchError):
class MeilisearchApiError(MeilisearchError):
"""Error sent by Meilisearch API"""

def __init__(self, error: str, request: Response) -> None:
Expand All @@ -37,20 +37,20 @@ def __init__(self, error: str, request: Response) -> None:

def __str__(self) -> str:
if self.code and self.link:
return f"MeiliSearchApiError. Error code: {self.code}. Error message: {self.message} Error documentation: {self.link} Error type: {self.type}"
return f"MeilisearchApiError. Error code: {self.code}. Error message: {self.message} Error documentation: {self.link} Error type: {self.type}"

return f"MeiliSearchApiError. {self.message}"
return f"MeilisearchApiError. {self.message}"


class MeiliSearchCommunicationError(MeiliSearchError):
class MeilisearchCommunicationError(MeilisearchError):
"""Error when connecting to Meilisearch"""

def __str__(self) -> str:
return f"MeiliSearchCommunicationError, {self.message}"
return f"MeilisearchCommunicationError, {self.message}"


class MeiliSearchTimeoutError(MeiliSearchError):
class MeilisearchTimeoutError(MeilisearchError):
"""Error when Meilisearch operation takes longer than expected"""

def __str__(self) -> str:
return f"MeiliSearchTimeoutError, {self.message}"
return f"MeilisearchTimeoutError, {self.message}"
Loading