Skip to content

Commit

Permalink
fix: error handling in submission downloadThread (#227)
Browse files Browse the repository at this point in the history
* fix: error handling in downloadThread

* fix: proper log error for the exception

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: sujanadh <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 3876e62 commit 16ddabc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions osm_fieldwork/OdkCentral.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def downloadThread(project_id: int, xforms: list, odk_credentials: dict, filters
form = OdkForm(odk_credentials["url"], odk_credentials["user"], odk_credentials["passwd"])
# submissions = form.getSubmissions(project_id, task, 0, False, True)
subs = form.listSubmissions(project_id, task, filters)
if type(subs) == dict:
log.error(f"{subs['message']}, {subs['code']} ")
if not subs:
log.error(f"Failed to get submissions for project ({project_id}) task ({task})")
continue
# log.debug(f"There are {len(subs)} submissions for {task}")
if len(subs) > 0:
data += subs
if len(subs["value"]) > 0:
data += subs["value"]
# log.debug(f"There are {len(xforms)} Xforms, and {len(submissions)} submissions total")
timer.stop()
return data
Expand Down Expand Up @@ -669,12 +669,14 @@ def listSubmissions(self, projectId: int, xform: str, filters: dict = None):
(json): The JSON of Submissions.
"""
url = f"{self.base}projects/{projectId}/forms/{xform}.svc/Submissions"
result = self.session.get(url, params=filters, verify=self.verify)
if result.ok:
try:
result = self.session.get(url, params=filters, verify=self.verify)
result.raise_for_status() # Raise an error for non-2xx status codes
self.submissions = result.json()
return self.submissions

return {}
except Exception as e:
log.error(f"Error fetching submissions: {e}")
return {}

def listAssignments(
self,
Expand Down

0 comments on commit 16ddabc

Please sign in to comment.