-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling in downloadThread #227
Conversation
osm_fieldwork/OdkCentral.py
Outdated
@@ -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: | |||
if subs == {}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if subs == {}
, then subs["message"]
will not exist, so the log.error will fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What format is the error JSON if getting the submission fails?
You could probably do something like:
if isinstance(subs, dict) and (error_code := subs.get("code", False)):
log.error(
f"Failed to get submissions for project ({project_id}) task ({task})"
f" with error code {error_code}: {subs.get('message')}"
)
continue
if len(subs.get("value"), []) > 0:
data += subs["value"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you are right.
our listSubmissions() looks like this:
url = f"{self.base}projects/{projectId}/forms/{xform}.svc/Submissions"
result = self.session.get(url, params=filters, verify=self.verify)
if result.ok:
self.submissions = result.json()
return self.submissions
return {}
if result is not ok that means status code returned by the server is not in the range of 200-299,
empty dict is returned. so there wont be message and status code.
is this log okay?
if subs == {}:
log.error(f"Failed to get submissions for project ({project_id}) task ({task})")
continue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't give the reason for failure like the code above, but yes it's fine too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment
osm_fieldwork/OdkCentral.py
Outdated
@@ -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: | |||
if subs == {}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What format is the error JSON if getting the submission fails?
You could probably do something like:
if isinstance(subs, dict) and (error_code := subs.get("code", False)):
log.error(
f"Failed to get submissions for project ({project_id}) task ({task})"
f" with error code {error_code}: {subs.get('message')}"
)
continue
if len(subs.get("value"), []) > 0:
data += subs["value"]
for more information, see https://pre-commit.ci
Update
fixed issue prevailing in handling the json returned from listSubmission.