mayureshagashe2105 commited on
Commit
5d8f196
·
1 Parent(s): edf4ce0

Add Config and Exception Handlers

Browse files
backend/core/ConfigEnv.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Config class for handling env variables.
2
+ """
3
+ from functools import lru_cache
4
+
5
+ from pydantic import BaseSettings
6
+
7
+
8
+ class Settings(BaseSettings):
9
+ HOSTNAME: str
10
+ DATABASE: str
11
+ UID: str
12
+ PASSWORD: str
13
+ ALGORITHM:str
14
+ JWT_SECRET_KEY:str
15
+ JWT_REFRESH_SECRET_KEY:str
16
+ # OPENAI_KEY:str
17
+ APP_ID:str
18
+ USER_ID:str
19
+ MODEL_ID:str
20
+ CLARIFAI_PAT:str
21
+ MODEL_VERSION_ID:str
22
+
23
+ class Config:
24
+ env_file = ".env"
25
+
26
+
27
+ @lru_cache()
28
+ def get_settings():
29
+ return Settings()
30
+
31
+
32
+ config = get_settings()
backend/core/ExceptionHandlers.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from docguptea import app
2
+ from .Exceptions import *
3
+
4
+ from fastapi.responses import JSONResponse
5
+ from fastapi.requests import Request
6
+ from fastapi import status
7
+
8
+
9
+
10
+ @app.exception_handler(ExistingUserException)
11
+ async def handle_existing_user_found(request: Request, exec: ExistingUserException):
12
+ return JSONResponse(status_code=status.HTTP_226_IM_USED,
13
+ content=repr(exec)
14
+ )
15
+
16
+
17
+ @app.exception_handler(InvalidCredentialsException)
18
+ async def handle_login_failed(request: Request, exec: InvalidCredentialsException):
19
+ return JSONResponse(status_code=status.HTTP_403_FORBIDDEN,
20
+ content=repr(exec)
21
+ )
22
+
23
+ @app.exception_handler(InfoNotFoundException)
24
+ async def handle_info_not_found(request: Request, exec: InfoNotFoundException):
25
+ return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
26
+ content=repr(exec)
27
+ )
backend/core/__init__.py ADDED
File without changes