from core.models.wrapper.responses import Response, Meta from fastapi.responses import JSONResponse class CustomExceptionHandler(Exception): def __init__(self, status_code: int, response: Response): self.status_code = status_code self.response = response def result(self) -> JSONResponse: return JSONResponse(status_code=self.status_code, content=self.response.model_dump(exclude_none=True)) def not_authenticated_error(): response = Response(status=401, error=True, message="Token is not valid") raise CustomExceptionHandler(status_code=401, response=response) def incorrect_login(): response = Response(status=401, error=True, message="Incorrect login") raise CustomExceptionHandler(status_code=401, response=response) def chat_not_found(): response = Response(status=404, error=True, message="Chat not found") raise CustomExceptionHandler(status_code=404, response=response) def not_a_member_of_chat(): response = Response(status=403, error=True, message="You are not a member of this chat") raise CustomExceptionHandler(status_code=403, response=response)