"""Exceptions for Jon's Pushover MCP Server."""
class ServerError(Exception):
"""Base exception for server errors.
Attributes:
message: Human-readable error description
is_retryable: Whether the error might succeed on retry
"""
def __init__(
self,
message: str,
is_retryable: bool = False,
) -> None:
super().__init__(message)
self.message = message
self.is_retryable = is_retryable
def __str__(self) -> str:
return self.message
class NotInitializedError(Exception):
"""Raised when the server is not properly initialized."""
pass
class PushoverError(ServerError):
"""Raised when the Pushover API returns an error.
Attributes:
message: Human-readable error description
status_code: HTTP status code from the API response
errors: List of error messages from Pushover API
"""
def __init__(
self,
message: str,
status_code: int | None = None,
errors: list[str] | None = None,
) -> None:
super().__init__(message, is_retryable=status_code in (429, 500, 502, 503, 504))
self.status_code = status_code
self.errors = errors or []
def __str__(self) -> str:
if self.errors:
return f"{self.message}: {', '.join(self.errors)}"
return self.message