File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,20 @@ async def docs_redirect():
6363@app .get ("/health" )
6464async def health ():
6565 """Get health of instance."""
66- kobo = requests .get (f"https://kobo.ifrc.org/api/v2" )
67- return JSONResponse (
68- status_code = 200 ,
69- content = {"kobo-connect" : 200 , "kobo.ifrc.org" : kobo .status_code },
70- )
66+ logger .info ("Health check initiated" )
67+ try :
68+ kobo = requests .get (f"https://kobo.ifrc.org/api/v2" , timeout = 10 )
69+ logger .info (f"Kobo API health check completed with status: { kobo .status_code } " )
70+ return JSONResponse (
71+ status_code = 200 ,
72+ content = {"kobo-connect" : 200 , "kobo.ifrc.org" : kobo .status_code },
73+ )
74+ except requests .exceptions .RequestException as e :
75+ logger .error (f"Kobo API health check failed: { str (e )} " )
76+ return JSONResponse (
77+ status_code = 200 ,
78+ content = {"kobo-connect" : 200 , "kobo.ifrc.org" : "unavailable" },
79+ )
7180
7281
7382if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -98,7 +98,14 @@ async def kobo_to_121(
9898 ):
9999 payload [target_field ] = kobo_data [kobo_field ]
100100 else :
101- payload [target_field ] = attachments [kobo_value_url ]["url" ]
101+ try :
102+ payload [target_field ] = attachments [kobo_value_url ]["url" ]
103+ except KeyError :
104+ logger .warning (
105+ f"Could not retrieve attachment URL for field '{ target_field } ' with value '{ kobo_value_url } '" ,
106+ extra = extra_logs ,
107+ )
108+ payload [target_field ] = "could not retrieve attachment url from kobo"
102109
103110 payload ["referenceId" ] = referenceId
104111
You can’t perform that action at this time.
0 commit comments