Spaces:
Runtime error
Runtime error
phuochungus
commited on
Commit
•
55b3449
1
Parent(s):
7ea3581
fix middleware
Browse files- app/dependencies.py +6 -8
app/dependencies.py
CHANGED
@@ -16,28 +16,26 @@ def get_current_user(
|
|
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",
|
35 |
headers={"WWW-Authenticate": "Bearer"},
|
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
|
|
|
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 as e:
|
20 |
+
logger.warning(e)
|
21 |
raise HTTPException(
|
22 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
23 |
detail="Token expired",
|
24 |
headers={"WWW-Authenticate": "Bearer"},
|
25 |
)
|
26 |
+
except InvalidIdTokenError as e:
|
27 |
+
logger.warning(e)
|
28 |
raise HTTPException(
|
29 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
30 |
detail="Invalid token",
|
31 |
headers={"WWW-Authenticate": "Bearer"},
|
32 |
)
|
33 |
+
except ValueError as e:
|
34 |
+
logger.warning(e)
|
35 |
raise HTTPException(
|
36 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
37 |
detail="Invalid token",
|
38 |
headers={"WWW-Authenticate": "Bearer"},
|
39 |
)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
return payload
|