from httpx import HTTPError
[docs]
class InvalidMattermostError(Exception):
"""
Raised when mattermost returns an invalid error
"""
def __init__(self, message: str, status_code: int):
super().__init__(message)
self.status_code: int = status_code
class MattermostError(HTTPError):
"""
Base class for all known mattermost errors
"""
def __init__(
self,
message: str,
status_code: int,
error_id: str,
request_id: str,
is_oauth_error: bool,
):
super().__init__(message)
self.status_code: int = status_code
self.error_id: str = error_id
self.request_id: str = request_id
self.is_oauth_error: bool = is_oauth_error
[docs]
class UnknownMattermostError(MattermostError):
"""
Raised when mattermost returns a status code that is not known
"""
[docs]
class InvalidOrMissingParameters(MattermostError):
"""
Raised when mattermost returns a
400 Invalid or missing parameters in URL or request body
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=400,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class NoAccessTokenProvided(MattermostError):
"""
Raised when mattermost returns a
401 No access token provided
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=401,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class NotEnoughPermissions(MattermostError):
"""
Raised when mattermost returns a
403 Do not have appropriate permissions
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=403,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class ResourceNotFound(MattermostError):
"""
Raised when mattermost returns a
404 Resource not found
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=404,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class MethodNotAllowed(MattermostError):
"""
Raised when mattermost returns a
405 Method Not Allowed
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=405,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class ContentTooLarge(MattermostError):
"""
Raised when mattermost returns a
413 Content too large
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=413,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
[docs]
class TooManyRequests(MattermostError):
"""
Raised when the server returns a
429 Too Many Requests
Mattermost's rate limiter responds with a plain text body rather than
the standard JSON error, so ``error_id`` and ``request_id`` may be None.
``retry_after`` holds the server-provided wait time in seconds, taken
from the ``Retry-After`` or ``X-RateLimit-Reset`` header if present.
"""
def __init__(
self,
message: str,
retry_after: float | None,
error_id: str | None = None,
request_id: str | None = None,
is_oauth_error: bool = False,
):
super().__init__(
message=message,
status_code=429,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)
self.retry_after: float | None = retry_after
[docs]
class FeatureDisabled(MattermostError):
"""
Raised when mattermost returns a
501 Feature is disabled
"""
def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool):
super().__init__(
message=message,
status_code=501,
error_id=error_id,
request_id=request_id,
is_oauth_error=is_oauth_error,
)