Skip to content

Commit

Permalink
Merge a29d6f4 into e28232f
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanklee86 committed Jun 3, 2021
2 parents e28232f + a29d6f4 commit 02b1844
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions UnleashClient/api/register.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from datetime import datetime, timezone
import requests
from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, InvalidHeader
from UnleashClient.constants import SDK_NAME, SDK_VERSION, REQUEST_TIMEOUT, APPLICATION_HEADERS, REGISTER_URL
from UnleashClient.utils import LOGGER, log_resp_info

Expand Down Expand Up @@ -55,6 +56,9 @@ def register_client(url: str,
LOGGER.info("Unleash Client successfully registered!")

return True
except (MissingSchema, InvalidSchema, InvalidHeader, InvalidURL) as exc:
LOGGER.exception("Unleash Client registration failed fatally due to exception: %s", exc)
raise exc
except requests.RequestException as exc:
LOGGER.exception("Unleash Client registration failed due to exception: %s", exc)

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Next version

## Upcoming
* (Minor) `initialize_client()` will raise exception if UnleashClient is configured with an invalid URL.
* (Minor) Exclude test package from dist & wheel. Thanks @ameyajoshi99!
* (Minor) Allow users to specify log-level for when `is_enabled()` or `get_varients()` calls fail.

## v4.2.0
Expand Down
14 changes: 14 additions & 0 deletions tests/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,17 @@ def test_uc_server_error_recovery(unleash_client):
responses.add(responses.GET, URL + FEATURES_URL, json=MOCK_FEATURE_RESPONSE, status=200)
time.sleep(20)
assert unleash_client.is_enabled("testFlag")


def test_uc_with_invalid_url():
unleash_client = UnleashClient("thisisnotavalidurl", APP_NAME)

with pytest.raises(ValueError):
unleash_client.initialize_client()


def test_uc_with_network_error():
unleash_client = UnleashClient("https://thisisavalidurl.com", APP_NAME)
unleash_client.initialize_client()

assert unleash_client.is_enabled

0 comments on commit 02b1844

Please sign in to comment.