error.py 546 B

123456789101112131415161718192021222324252627282930
  1. from dataclasses import dataclass
  2. class LCException(Exception):
  3. def to_json(self) -> dict:
  4. return {"error": str(self)}
  5. @dataclass
  6. class UserExists(LCException):
  7. name: str
  8. def __str__(self):
  9. return f"A user named {self.name} already exists."
  10. @dataclass
  11. class NoSuchUser(LCException):
  12. name: str
  13. def __str__(self):
  14. return f"No user named {self.name} exists."
  15. @dataclass
  16. class BadPassword(LCException):
  17. name: str
  18. def __str__(self):
  19. return f"Wrong password for user {self.name}."