Skip to content

Errors api

Errors

These are the exceptions raised by the SDK. MeilisearchApiError is raised when Meilisearch returns an error response, and MeilisearchCommunicationError is raised when Meilisearch cannot be reached at all. The token errors are raised when generating or validating tenant tokens.

Errors API

meilisearch_python_sdk.errors

BatchNotFoundError

Bases: Exception

Source code in meilisearch_python_sdk/errors.py
class BatchNotFoundError(Exception):
    pass

InvalidDocumentError

Bases: Exception

Error for documents that are not in a valid format for Meilisearch.

Source code in meilisearch_python_sdk/errors.py
class InvalidDocumentError(Exception):
    """Error for documents that are not in a valid format for Meilisearch."""

    pass

InvalidRestriction

Bases: Exception

Source code in meilisearch_python_sdk/errors.py
class InvalidRestriction(Exception):
    pass

MeilisearchError

Bases: Exception

Generic class for Meilisearch error handling.

Source code in meilisearch_python_sdk/errors.py
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}."

message instance-attribute

message = message

__init__

__init__(message: str) -> None
Source code in meilisearch_python_sdk/errors.py
def __init__(self, message: str) -> None:
    self.message = message
    super().__init__(self.message)

__str__

__str__() -> str
Source code in meilisearch_python_sdk/errors.py
def __str__(self) -> str:
    return f"MeilisearchError. Error message: {self.message}."

MeilisearchApiError

Bases: MeilisearchError

Error sent by Meilisearch API.

Source code in meilisearch_python_sdk/errors.py
class MeilisearchApiError(MeilisearchError):
    """Error sent by Meilisearch API."""

    def __init__(self, error: str, response: Response) -> None:
        self.status_code = response.status_code
        self.code = ""
        self.message = ""
        self.link = ""
        self.error_type = ""
        error_json = None
        if response.content:
            try:
                error_json = response.json()
            except json.JSONDecodeError:
                error_json = None
        if isinstance(error_json, dict):
            self.message = f"Error message: {error_json.get('message') or ''}"
            self.code = f"{error_json.get('code') or ''}"
            self.error_type = f"{error_json.get('type') or ''}"
            self.link = f"Error documentation: {error_json.get('link') or ''}"
        else:
            self.message = error
        super().__init__(self.message)

    def __str__(self) -> str:
        return f"MeilisearchApiError.{self.code} {self.message} {self.error_type} {self.link}"

status_code instance-attribute

status_code = response.status_code

code instance-attribute

code = ''

message instance-attribute

message = ''
link = ''

error_type instance-attribute

error_type = ''

__init__

__init__(error: str, response: Response) -> None
Source code in meilisearch_python_sdk/errors.py
def __init__(self, error: str, response: Response) -> None:
    self.status_code = response.status_code
    self.code = ""
    self.message = ""
    self.link = ""
    self.error_type = ""
    error_json = None
    if response.content:
        try:
            error_json = response.json()
        except json.JSONDecodeError:
            error_json = None
    if isinstance(error_json, dict):
        self.message = f"Error message: {error_json.get('message') or ''}"
        self.code = f"{error_json.get('code') or ''}"
        self.error_type = f"{error_json.get('type') or ''}"
        self.link = f"Error documentation: {error_json.get('link') or ''}"
    else:
        self.message = error
    super().__init__(self.message)

__str__

__str__() -> str
Source code in meilisearch_python_sdk/errors.py
def __str__(self) -> str:
    return f"MeilisearchApiError.{self.code} {self.message} {self.error_type} {self.link}"

MeilisearchCommunicationError

Bases: MeilisearchError

Error when connecting to Meilisearch.

Source code in meilisearch_python_sdk/errors.py
class MeilisearchCommunicationError(MeilisearchError):
    """Error when connecting to Meilisearch."""

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

__str__

__str__() -> str
Source code in meilisearch_python_sdk/errors.py
def __str__(self) -> str:
    return f"MeilisearchCommunicationError, {self.message}"

MeilisearchTaskFailedError

Bases: MeilisearchError

Error when a task is in the failed status.

Source code in meilisearch_python_sdk/errors.py
class MeilisearchTaskFailedError(MeilisearchError):
    """Error when a task is in the failed status."""

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

__str__

__str__() -> str
Source code in meilisearch_python_sdk/errors.py
def __str__(self) -> str:
    return f"MeilisearchTaskFailedError, {self.message}"

MeilisearchTimeoutError

Bases: MeilisearchError

Error when Meilisearch operation takes longer than expected.

Source code in meilisearch_python_sdk/errors.py
class MeilisearchTimeoutError(MeilisearchError):
    """Error when Meilisearch operation takes longer than expected."""

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

__str__

__str__() -> str
Source code in meilisearch_python_sdk/errors.py
def __str__(self) -> str:
    return f"MeilisearchTimeoutError, {self.message}"

PayloadTooLarge

Bases: Exception

Error when the payload is larger than the allowed payload size.

Source code in meilisearch_python_sdk/errors.py
class PayloadTooLarge(Exception):
    """Error when the payload is larger than the allowed payload size."""

    pass

InvalidTokenError

Bases: Exception

Base exception when decode() fails on a token

Source code in meilisearch_python_sdk/errors.py
class InvalidTokenError(Exception):
    """Base exception when ``decode()`` fails on a token"""

    pass

DecodeError

Bases: InvalidTokenError

Raised when a token cannot be decoded because it failed validation

Source code in meilisearch_python_sdk/errors.py
class DecodeError(InvalidTokenError):
    """Raised when a token cannot be decoded because it failed validation"""

    pass

InvalidIssuedAtError

Bases: InvalidTokenError

Raised when a token's iat claim is non-numeric

Source code in meilisearch_python_sdk/errors.py
class InvalidIssuedAtError(InvalidTokenError):
    """Raised when a token's ``iat`` claim is non-numeric"""

    pass

InvalidSignatureError

Bases: DecodeError

Raised when a token's signature doesn't match the one provided as part of the token.

Source code in meilisearch_python_sdk/errors.py
class InvalidSignatureError(DecodeError):
    """Raised when a token's signature doesn't match the one provided as part of the token."""

    pass

ImmatureSignatureError

Bases: InvalidTokenError

Raised when a token's nbf or iat claims represent a time in the future

Source code in meilisearch_python_sdk/errors.py
class ImmatureSignatureError(InvalidTokenError):
    """Raised when a token's ``nbf`` or ``iat`` claims represent a time in the future"""

    pass

ExpiredSignatureError

Bases: InvalidTokenError

Raised when a token's exp claim indicates it has expired

Source code in meilisearch_python_sdk/errors.py
class ExpiredSignatureError(InvalidTokenError):
    """Raised when a token's ``exp`` claim indicates it has expired"""

    pass

InvalidSubjectError

Bases: InvalidTokenError

Raised when a token's sub claim is not a string

Source code in meilisearch_python_sdk/errors.py
class InvalidSubjectError(InvalidTokenError):
    """Raised when a token's ``sub`` claim is not a string"""

    pass

InvalidJTIError

Bases: InvalidTokenError

Raised when a token's jti claim is not a string

Source code in meilisearch_python_sdk/errors.py
class InvalidJTIError(InvalidTokenError):
    """Raised when a token's ``jti`` claim is not a string"""

    pass