Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Mar 2, 2024
1 parent 972fb2d commit 9aa7a8d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,11 @@ async def get_info(renpho: RenphoWeight = Depends(get_current_user)):
info = await renpho.get_info()
if info:
return APIResponse(status="success", message="Fetched user info.", data=info)
renpho.close()
await renpho.close()
return APIResponse(status="error", message="User info not found.")
except Exception as e:
logger.error(f"Error fetching user info: {e}")
renpho.close()
await renpho.close()
return APIResponse(status="error", message="Failed to fetch user info.")

@app.get("/users", response_model=APIResponse)
Expand All @@ -715,11 +715,11 @@ async def get_scale_users(request: Request, renpho: RenphoWeight = Depends(get_c
users = await renpho.get_scale_users()
if users:
return APIResponse(status="success", message="Fetched scale users.", data={"users": users})
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Users not found")
except Exception as e:
logger.error(f"Error fetching scale users: {e}")
renpho.close()
await renpho.close()
return APIResponse(status="error", message=str(e))

@app.get("/measurements", response_model=APIResponse)
Expand All @@ -728,10 +728,10 @@ async def get_measurements(request: Request, renpho: RenphoWeight = Depends(get_
measurements = await renpho.get_measurements()
if measurements:
return APIResponse(status="success", message="Fetched measurements.", data={"measurements": measurements})
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Measurements not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching measurements: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -741,10 +741,10 @@ async def get_weight(request: Request, renpho: RenphoWeight = Depends(get_curren
weight = await renpho.get_weight()
if weight:
return APIResponse(status="success", message="Fetched weight.", data={"weight": weight})
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Weight not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching weight: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -754,10 +754,10 @@ async def get_specific_metric(request: Request, metric: str, metric_id: str, ren
specific_metric = await renpho.get_specific_metric(metric, metric_id)
if specific_metric:
return APIResponse(status="success", message=f"Fetched specific metric: {metric} {metric_id}.", data={metric: specific_metric})
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail=f"Specific metric {metric} {metric_id} not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching specific metric: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -767,10 +767,10 @@ async def get_device_info(request: Request, renpho: RenphoWeight = Depends(get_c
device_info = await renpho.get_device_info()
if device_info:
return APIResponse(status="success", message="Fetched device info.", data=device_info)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Device info not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching device info: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -780,10 +780,10 @@ async def list_latest_model(request: Request, renpho: RenphoWeight = Depends(get
latest_model = await renpho.list_latest_model()
if latest_model:
return APIResponse(status="success", message="Fetched latest model.", data=latest_model)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Latest model not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching latest model: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -793,10 +793,10 @@ async def list_girth(request: Request, renpho: RenphoWeight = Depends(get_curren
girth_info = await renpho.list_girth()
if girth_info:
return APIResponse(status="success", message="Fetched girth info.", data=girth_info)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Girth info not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching girth info: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -806,10 +806,10 @@ async def list_girth_goal(request: Request, renpho: RenphoWeight = Depends(get_c
girth_goal = await renpho.list_girth_goal()
if girth_goal:
return APIResponse(status="success", message="Fetched girth goal.", data=girth_goal)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Girth goal not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching girth goal: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -819,10 +819,10 @@ async def list_growth_record(request: Request, renpho: RenphoWeight = Depends(ge
growth_record = await renpho.list_growth_record()
if growth_record:
return APIResponse(status="success", message="Fetched growth record.", data=growth_record)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Growth record not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching growth record: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -832,10 +832,10 @@ async def message_list(request: Request, renpho: RenphoWeight = Depends(get_curr
messages = await renpho.message_list()
if messages:
return APIResponse(status="success", message="Fetched message list.", data=messages)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Message list not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching message list: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -848,7 +848,7 @@ async def reach_goal(request: Request, renpho: RenphoWeight = Depends(get_curren
renpho.close()
raise HTTPException(status_code=404, detail="Reach goal not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching reach goal: {e}")
return APIResponse(status="error", message=str(e))

Expand All @@ -858,9 +858,9 @@ async def request_user(request: Request, renpho: RenphoWeight = Depends(get_curr
user_request = await renpho.request_user()
if user_request:
return APIResponse(status="success", message="Fetched request user.", data=user_request)
renpho.close()
await renpho.close()
raise HTTPException(status_code=404, detail="Request user not found")
except Exception as e:
renpho.close()
await renpho.close()
logger.error(f"Error fetching request user: {e}")
return APIResponse(status="error", message=str(e))

0 comments on commit 9aa7a8d

Please sign in to comment.