Skip to content
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

Show detailed exception only when needed #230

Merged
merged 12 commits into from
Feb 9, 2024
18 changes: 17 additions & 1 deletion commcare_export/commcare_hq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import copy
import logging
import sys
import time
from collections import OrderedDict
from math import ceil
Expand Down Expand Up @@ -151,7 +152,22 @@ def _get(resource, params=None):
resource_url, params=params, auth=self.__auth, timeout=60
)
if self._should_raise_for_status(response):
response.raise_for_status()
try:
response.raise_for_status()
except Exception as e:
# for non-verbose output, skip the stacktrace
if not logger.isEnabledFor(logging.DEBUG):
if isinstance(e, requests.exceptions.HTTPError) and response.status_code == 401:
logger.error(
f"#{e}. Please ensure that your CommCare HQ credentials are correct & valid for "
f"the auth-mode passed. Also, Verify that your account has the necessary "
mkangia marked this conversation as resolved.
Show resolved Hide resolved
f"permissions to access the DET tool."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

("the DET tool" means "the data export tool tool".) But I'm wondering whether the user knows that Dimagi internally refers to this as "the DET". In help text this command refers to itself as "commcare-export" or "the commcare-export tool". I think this text might be more familiar to a user:

Suggested change
f"permissions to access the DET tool."
f"permissions to use commcare-export."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thank you

5d99505

)
else:
logger.error(str(e))
sys.exit()
raise e

return response

response = _get(resource, params)
Expand Down
Loading