Source code for codingame.exceptions

__all__ = (
    "CodinGameAPIError",
    "LoginError",
    "EmailRequired",
    "MalformedEmail",
    "PasswordRequired",
    "EmailNotLinked",
    "IncorrectPassword",
    "LoginRequired",
    "NotFound",
    "CodinGamerNotFound",
    "ClashOfCodeNotFound",
    "ChallengeNotFound",
    "PuzzleNotFound",
)


[docs]class CodinGameAPIError(Exception): """Base exception for the CodinGame API.""" def __init__(self, message: str): self.message = message super().__init__(message)
[docs]class LoginError(CodinGameAPIError): """Raised when the login data is incorrect.""" @classmethod def from_id(cls, id: int, message: str): # pragma: no cover # unused since the login method changed errors = { 332: EmailRequired, 334: MalformedEmail, 336: PasswordRequired, 393: EmailNotLinked, 396: IncorrectPassword, 701: WrongCaptchaAnswer, } return errors.get(id, cls)(message)
[docs]class EmailRequired(LoginError): """Raised when the email given at login is empty."""
[docs]class MalformedEmail(LoginError): """Raised when the email given at login isn't well formed."""
[docs]class PasswordRequired(LoginError): """Raised when the password given at login is empty."""
[docs]class EmailNotLinked(LoginError): """Raised when the email given at login isn't linked to a CodinGamer account."""
[docs]class IncorrectPassword(LoginError): """Raised when the password given at login is incorrect."""
[docs]class WrongCaptchaAnswer(LoginError): """Raised when the captcha in the email/password login is incorrect. See :ref:`login` to fix this"""
[docs]class LoginRequired(LoginError): """Raised when an action requires the client to log in.""" def __init__(self, message: str = None): super().__init__( message or "You must be logged in to perform this action." )
[docs]class NotFound(CodinGameAPIError): """Raised when something isn't found.""" @classmethod def from_type(cls, type: str, message: str): errors = { "codingamer": CodinGamerNotFound, "clash_of_code": ClashOfCodeNotFound, "challenge": ChallengeNotFound, "puzzle": PuzzleNotFound, } return errors.get(type, cls)(message)
[docs]class CodinGamerNotFound(NotFound): """Raised when a CodinGamer isn't found."""
[docs]class ClashOfCodeNotFound(NotFound): """Raised when a Clash of Code isn't found."""
[docs]class ChallengeNotFound(NotFound): """Raised when a Challenge isn't found."""
[docs]class PuzzleNotFound(NotFound): """Raised when a Puzzle isn't found."""