zenaight commited on
Commit ·
646ae8e
1
Parent(s): 53c8a1f
Enhance error handling in user intent retrieval
Browse files- Added a try-except block in the `get_or_create_user_intent` function to handle exceptions during the retrieval of user intent records from the database.
- This change ensures that if no record exists, the function can gracefully proceed to create a new intent record, improving robustness and reliability in intent management.
- database.py +13 -8
database.py
CHANGED
|
@@ -242,14 +242,19 @@ async def get_or_create_user_intent(session_id: str, wa_id: str) -> dict:
|
|
| 242 |
"""
|
| 243 |
Fetch or create the intent record for this session.
|
| 244 |
"""
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
new_intent = {
|
| 254 |
"session_id": session_id,
|
| 255 |
"wa_id": wa_id,
|
|
|
|
| 242 |
"""
|
| 243 |
Fetch or create the intent record for this session.
|
| 244 |
"""
|
| 245 |
+
try:
|
| 246 |
+
resp = supabase \
|
| 247 |
+
.table("user_intents") \
|
| 248 |
+
.select("*") \
|
| 249 |
+
.eq("session_id", session_id) \
|
| 250 |
+
.single() \
|
| 251 |
+
.execute()
|
| 252 |
+
if resp.data:
|
| 253 |
+
return resp.data
|
| 254 |
+
except Exception as e:
|
| 255 |
+
# No record exists, create one
|
| 256 |
+
pass
|
| 257 |
+
|
| 258 |
new_intent = {
|
| 259 |
"session_id": session_id,
|
| 260 |
"wa_id": wa_id,
|