Spaces:
Runtime error
Runtime error
Commit
•
5dad19d
1
Parent(s):
102e541
debug
Browse files- app/__init__.py +2 -2
- app/dependencies.py +6 -3
- app/main.py +5 -0
app/__init__.py
CHANGED
@@ -11,8 +11,8 @@ from firebase_admin import firestore
|
|
11 |
from neo4j import GraphDatabase
|
12 |
|
13 |
|
14 |
-
|
15 |
-
logger.
|
16 |
|
17 |
|
18 |
load_dotenv()
|
|
|
11 |
from neo4j import GraphDatabase
|
12 |
|
13 |
|
14 |
+
logging.basicConfig(level=logging.DEBUG)
|
15 |
+
logger = logging.getLogger(__name__)
|
16 |
|
17 |
|
18 |
load_dotenv()
|
app/dependencies.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import Depends, HTTPException, status
|
|
2 |
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
3 |
from firebase_admin import auth
|
4 |
from firebase_admin.auth import ExpiredIdTokenError, InvalidIdTokenError
|
|
|
5 |
from . import db
|
6 |
|
7 |
security = HTTPBearer()
|
@@ -15,19 +16,19 @@ def get_current_user(
|
|
15 |
user_doc_ref = db.collection("user").document(payload["sub"]).get()
|
16 |
if not user_doc_ref.exists:
|
17 |
raise HTTPException(status_code=400, detail="User profile not found")
|
18 |
-
except ExpiredIdTokenError
|
19 |
raise HTTPException(
|
20 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
21 |
detail="Token expired",
|
22 |
headers={"WWW-Authenticate": "Bearer"},
|
23 |
)
|
24 |
-
except InvalidIdTokenError
|
25 |
raise HTTPException(
|
26 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
27 |
detail="Invalid token",
|
28 |
headers={"WWW-Authenticate": "Bearer"},
|
29 |
)
|
30 |
-
except ValueError
|
31 |
raise HTTPException(
|
32 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
33 |
detail="Invalid token",
|
@@ -35,6 +36,8 @@ def get_current_user(
|
|
35 |
)
|
36 |
|
37 |
except Exception as e:
|
|
|
|
|
38 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
39 |
|
40 |
return payload
|
|
|
2 |
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
3 |
from firebase_admin import auth
|
4 |
from firebase_admin.auth import ExpiredIdTokenError, InvalidIdTokenError
|
5 |
+
from app import logger
|
6 |
from . import db
|
7 |
|
8 |
security = HTTPBearer()
|
|
|
16 |
user_doc_ref = db.collection("user").document(payload["sub"]).get()
|
17 |
if not user_doc_ref.exists:
|
18 |
raise HTTPException(status_code=400, detail="User profile not found")
|
19 |
+
except ExpiredIdTokenError:
|
20 |
raise HTTPException(
|
21 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
22 |
detail="Token expired",
|
23 |
headers={"WWW-Authenticate": "Bearer"},
|
24 |
)
|
25 |
+
except InvalidIdTokenError:
|
26 |
raise HTTPException(
|
27 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
28 |
detail="Invalid token",
|
29 |
headers={"WWW-Authenticate": "Bearer"},
|
30 |
)
|
31 |
+
except ValueError:
|
32 |
raise HTTPException(
|
33 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
34 |
detail="Invalid token",
|
|
|
36 |
)
|
37 |
|
38 |
except Exception as e:
|
39 |
+
logger.info(e)
|
40 |
+
logger.error(e)
|
41 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
42 |
|
43 |
return payload
|
app/main.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi.responses import RedirectResponse
|
|
4 |
from app.graphdb.main import insert2PersonAndSetFriend, deleteFriend
|
5 |
from .routers import image, video, friend_request, me
|
6 |
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -23,3 +24,7 @@ def hello():
|
|
23 |
async def test():
|
24 |
await insert2PersonAndSetFriend("1", "2")
|
25 |
await deleteFriend("1", "2")
|
|
|
|
|
|
|
|
|
|
4 |
from app.graphdb.main import insert2PersonAndSetFriend, deleteFriend
|
5 |
from .routers import image, video, friend_request, me
|
6 |
|
7 |
+
import uvicorn
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
24 |
async def test():
|
25 |
await insert2PersonAndSetFriend("1", "2")
|
26 |
await deleteFriend("1", "2")
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|