1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- from dataclasses import dataclass
- @dataclass
- class LCRedirect(Exception):
- path: str
- def to_path(self) -> str:
- return self.path
- class LCException(Exception):
- def to_json(self) -> dict:
- return {"error": str(self)}
- def http_code(self) -> int:
- return 500
- @dataclass
- class UserExists(LCException):
- name: str
- def __str__(self):
- return f"A user named {self.name} already exists."
- @dataclass
- class NoSuchUser(LCException):
- name: str
- def __str__(self):
- return f"No user named {self.name} exists."
- def http_code(self) -> int:
- return 404
- @dataclass
- class BadPassword(LCException):
- name: str
- def __str__(self):
- return f"Wrong password for user {self.name}."
- def http_code(self) -> int:
- return 403
- @dataclass
- class NotImplemented(LCException):
- def __str__(self):
- return f"Bad request: no handler for route."
- def http_code(self) -> int:
- return 404
- @dataclass
- class BadPermissions(LCException):
- def __str__(self):
- return f"Insufficient permissions."
- def http_code(self) -> int:
- return 403
- @dataclass
- class BadContentType(LCException):
- content_type: str
- def __str__(self):
- return f"Bad content type for request: {self.content_type}"
- def http_code(self) -> int:
- return 403
- @dataclass
- class NoSuchInvite(LCException):
- invite: str
- def __str__(self):
- return f"No such invite code: {self.invite}."
- def http_code(self) -> int:
- return 404
- @dataclass
- class AlreadyUsedInvite(LCException):
- invite: str
- def __str__(self):
- return f"Invite code {self.invite} already taken."
- def http_code(self) -> int:
- return 403
|