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

exception handling in _get_flag and documentation update #1

Merged
merged 2 commits into from
Sep 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Your first feature flag
1. Create a new feature flag on your [dashboard](https://app.launchdarkly.com)
2. In your application code, use the feature's key to check wthether the flag is on for each user:

if client.get_flag("your.flag.key", {"key": "user@test.com"}, false):
if client.get_flag("your.flag.key", {"key": "user@test.com"}, False):
# application code to show the feature
else:
# the code to run if the feature is off
16 changes: 11 additions & 5 deletions ldclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ def _get_flag(self, key, user, default):
'User-Agent': 'PythonClient/' + __version__}
uri = self._config._base_uri + '/api/eval/features/' + key
r = self._session.get(uri, headers=hdrs, timeout = (self._config._connect, self._config._read))
dict = r.json()
val = _evaluate(dict, user)
if val is None:
return default
try:
dict = r.json()
except ValueError:
# expected if parsing a non 2xx response
logging.exception(
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea-- I'll also wrap all of get_flag with except: to handle other exception kinds.

'Received non 2xx HTTP response in get_flag. '
'Returning default value for flag. Check feature settings.'
)
return default
else:
return val
return _evaluate(dict, user) or default


def _param_for_user(feature, user):
if 'key' in user:
Expand Down