debug: comprehensive error handling and logging for list_goals
- try-catch around entire endpoint - try-catch for each goal progress update - Detailed error logging with traceback - Continue processing other goals if one fails - Clear error message to frontend This will show exact error location in logs.
This commit is contained in:
parent
1f4ee5021e
commit
210671059a
|
|
@ -161,6 +161,7 @@ def list_goals(session: dict = Depends(require_auth)):
|
||||||
"""List all goals for current user"""
|
"""List all goals for current user"""
|
||||||
pid = session['profile_id']
|
pid = session['profile_id']
|
||||||
|
|
||||||
|
try:
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
|
|
@ -176,13 +177,27 @@ def list_goals(session: dict = Depends(require_auth)):
|
||||||
""", (pid,))
|
""", (pid,))
|
||||||
|
|
||||||
goals = [r2d(row) for row in cur.fetchall()]
|
goals = [r2d(row) for row in cur.fetchall()]
|
||||||
|
print(f"[DEBUG] Loaded {len(goals)} goals for profile {pid}")
|
||||||
|
|
||||||
# Update current values for each goal
|
# Update current values for each goal
|
||||||
for goal in goals:
|
for goal in goals:
|
||||||
|
try:
|
||||||
_update_goal_progress(conn, pid, goal)
|
_update_goal_progress(conn, pid, goal)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[ERROR] Failed to update progress for goal {goal.get('id')}: {e}")
|
||||||
|
# Continue with other goals even if one fails
|
||||||
|
|
||||||
return goals
|
return goals
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[ERROR] list_goals failed: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500,
|
||||||
|
detail=f"Fehler beim Laden der Ziele: {str(e)}"
|
||||||
|
)
|
||||||
|
|
||||||
@router.post("/create")
|
@router.post("/create")
|
||||||
def create_goal(data: GoalCreate, session: dict = Depends(require_auth)):
|
def create_goal(data: GoalCreate, session: dict = Depends(require_auth)):
|
||||||
"""Create new goal"""
|
"""Create new goal"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user