Added data download ability

This commit is contained in:
2023-02-19 21:10:00 +00:00
parent 48f080de7c
commit c850726f91
64 changed files with 12734 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
""" This module includes the BaseException
"""
import json
from fastapi.responses import JSONResponse
class BaseException(Exception):
"""BaseException is the base class for all exceptions
:param Exception: inherits from python Exception class
"""
def __init__(self, status_code: int, message: str):
"""__init__ init the class with the status code and message
:param status_code: the status code of the response
:type status_code: int
:param message: the message of exception
:type message: str
"""
self.status_code = status_code
self.message = message
def json(self) -> JSONResponse:
"""json return the json of the exception
:return: json reponse of exception
:rtype: JSONResponse
"""
return JSONResponse(
status_code=self.status_code, content={"message": self.message}
)
def checkResponse(self, response: BaseException) -> bool:
"""checkResponse compare the response exception with the exception
:param response: the response exception
:type response: _type_
:return: if excepiton equals the response exception
:rtype: bool
"""
return (
response.status_code == self.status_code
and json.loads(response.content)["message"] == self.message
)

View File

@@ -0,0 +1,31 @@
from fastapi import Request
from fastapi.responses import JSONResponse
from fastapi_jwt_auth.exceptions import AuthJWTException
async def base_exception_handler(request: Request, exception: BaseException):
"""my_exception_handler handler for the raised exceptions
:param request: the request
:type request: Request
:param exception: the raised exception
:type exception: BaseException
:return: the exception in json format
:rtype: JSONResponse
"""
return exception.json()
async def auth_exception_handler(request: Request, exception: AuthJWTException):
"""auth_exception_handler handler for the raised exceptions
:param request: the request
:type request: Request
:param exception: the raised exception
:type exception: AuthJWTException
:return: the exception in json format
:rtype: JSONResponse
"""
return JSONResponse(
status_code=exception.status_code, content={"message": exception.message}
)

View File

@@ -0,0 +1,11 @@
from src.exceptions.base_exception import BaseException
class LoginException(BaseException):
"""LoginException exception raised when something went wrong during the login process
:param BaseException: inherits from BaseException
"""
def __init__(self, message: str = ""):
"""__init__ inits parent class with status code and message"""
super().__init__(400, message)