28 lines
901 B
Python
28 lines
901 B
Python
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)
|
|
|