Skip to content

Commit 01b3e09

Browse files
committed
refactor(provider): remove impossible error handling for Unleash
1 parent 9a579d6 commit 01b3e09

File tree

2 files changed

+2
-140
lines changed

2 files changed

+2
-140
lines changed

providers/openfeature-provider-unleash/src/openfeature/contrib/provider/unleash/flag_evaluation.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import json
44
from typing import Any, Callable, Optional, Protocol
55

6-
import requests
76
from UnleashClient import UnleashClient
87

98
from openfeature.evaluation_context import EvaluationContext
109
from openfeature.exception import (
11-
FlagNotFoundError,
1210
GeneralError,
1311
ParseError,
1412
TypeMismatchError,
@@ -76,11 +74,7 @@ def resolve_boolean_details(
7674
"app_name": self._provider.app_name,
7775
},
7876
)
79-
except requests.exceptions.HTTPError as e:
80-
if e.response and e.response.status_code == 404:
81-
raise FlagNotFoundError(f"Flag not found: {flag_key}") from e
82-
raise GeneralError(f"HTTP error: {e}") from e
83-
except (FlagNotFoundError, TypeMismatchError, ParseError, GeneralError):
77+
except (TypeMismatchError, ParseError, GeneralError):
8478
raise
8579
except Exception as e:
8680
raise GeneralError(f"Unexpected error: {e}") from e
@@ -224,11 +218,7 @@ def _resolve_variant_flag(
224218
"app_name": self._provider.app_name,
225219
},
226220
)
227-
except requests.exceptions.HTTPError as e:
228-
if e.response and e.response.status_code == 404:
229-
raise FlagNotFoundError(f"Flag not found: {flag_key}") from e
230-
raise GeneralError(f"HTTP error: {e}") from e
231-
except (FlagNotFoundError, TypeMismatchError, ParseError, GeneralError):
221+
except (TypeMismatchError, ParseError, GeneralError):
232222
raise
233223
except Exception as e:
234224
raise GeneralError(f"Unexpected error: {e}") from e

providers/openfeature-provider-unleash/tests/test_flag_evaluation.py

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
from unittest.mock import Mock, patch
44

55
import pytest
6-
import requests
76

87
from openfeature.contrib.provider.unleash import UnleashProvider
98
from openfeature.evaluation_context import EvaluationContext
109
from openfeature.exception import (
11-
FlagNotFoundError,
12-
GeneralError,
1310
ParseError,
1411
TypeMismatchError,
1512
)
@@ -37,30 +34,6 @@ def test_resolve_boolean_details():
3734
assert flag.reason == Reason.TARGETING_MATCH
3835

3936

40-
def test_resolve_boolean_details_error():
41-
"""Test that FlagEvaluator handles errors gracefully."""
42-
mock_client = Mock()
43-
mock_client.is_enabled.side_effect = requests.exceptions.ConnectionError(
44-
"Connection error"
45-
)
46-
47-
with patch(
48-
"openfeature.contrib.provider.unleash.UnleashClient"
49-
) as mock_unleash_client:
50-
mock_unleash_client.return_value = mock_client
51-
52-
provider = UnleashProvider(
53-
url="http://localhost:4242", app_name="test-app", api_token="test-token"
54-
)
55-
provider.initialize()
56-
57-
with pytest.raises(GeneralError) as exc_info:
58-
provider.resolve_boolean_details("test_flag", True)
59-
assert "Connection error" in str(exc_info.value)
60-
61-
provider.shutdown()
62-
63-
6437
@pytest.mark.parametrize(
6538
"method_name, payload_value, expected_value, default_value",
6639
[
@@ -195,66 +168,6 @@ def test_value_conversion_errors(
195168
provider.shutdown()
196169

197170

198-
@pytest.mark.parametrize(
199-
"method_name, mock_side_effect, default_value, expected_error_message, expected_exception",
200-
[
201-
(
202-
"resolve_string_details",
203-
requests.exceptions.HTTPError(
204-
"404 Client Error: Not Found", response=Mock(status_code=404)
205-
),
206-
"default",
207-
"Flag not found",
208-
"FlagNotFoundError",
209-
),
210-
(
211-
"resolve_boolean_details",
212-
requests.exceptions.ConnectionError("Connection error"),
213-
True,
214-
"Connection error",
215-
"GeneralError",
216-
),
217-
],
218-
)
219-
def test_general_errors(
220-
method_name,
221-
mock_side_effect,
222-
default_value,
223-
expected_error_message,
224-
expected_exception,
225-
):
226-
"""Test that FlagEvaluator handles general errors correctly."""
227-
mock_client = Mock()
228-
229-
if method_name == "resolve_boolean_details":
230-
mock_client.is_enabled.side_effect = mock_side_effect
231-
else:
232-
mock_client.get_variant.side_effect = mock_side_effect
233-
234-
with patch(
235-
"openfeature.contrib.provider.unleash.UnleashClient"
236-
) as mock_unleash_client:
237-
mock_unleash_client.return_value = mock_client
238-
239-
provider = UnleashProvider(
240-
url="http://localhost:4242", app_name="test-app", api_token="test-token"
241-
)
242-
provider.initialize()
243-
244-
method = getattr(provider, method_name)
245-
246-
if expected_exception == "FlagNotFoundError":
247-
with pytest.raises(FlagNotFoundError) as exc_info:
248-
method("non_existent_flag", default_value)
249-
assert expected_error_message in str(exc_info.value)
250-
else:
251-
with pytest.raises(GeneralError) as exc_info:
252-
method("test_flag", default_value)
253-
assert expected_error_message in str(exc_info.value)
254-
255-
provider.shutdown()
256-
257-
258171
def test_edge_cases():
259172
"""Test FlagEvaluator with edge cases and boundary conditions."""
260173
mock_client = Mock()
@@ -295,47 +208,6 @@ def test_edge_cases():
295208
provider.shutdown()
296209

297210

298-
@pytest.mark.parametrize(
299-
"mock_side_effect, expected_error_message",
300-
[
301-
(
302-
requests.exceptions.HTTPError(
303-
"429 Too Many Requests", response=Mock(status_code=429)
304-
),
305-
"HTTP error",
306-
),
307-
(
308-
requests.exceptions.Timeout("Request timeout"),
309-
"Unexpected error",
310-
),
311-
(
312-
requests.exceptions.SSLError("SSL certificate error"),
313-
"Unexpected error",
314-
),
315-
],
316-
)
317-
def test_network_errors(mock_side_effect, expected_error_message):
318-
"""Test that FlagEvaluator handles network errors correctly."""
319-
mock_client = Mock()
320-
mock_client.is_enabled.side_effect = mock_side_effect
321-
322-
with patch(
323-
"openfeature.contrib.provider.unleash.UnleashClient"
324-
) as mock_unleash_client:
325-
mock_unleash_client.return_value = mock_client
326-
327-
provider = UnleashProvider(
328-
url="http://localhost:4242", app_name="test-app", api_token="test-token"
329-
)
330-
provider.initialize()
331-
332-
with pytest.raises(GeneralError) as exc_info:
333-
provider.resolve_boolean_details("test_flag", True)
334-
assert expected_error_message in str(exc_info.value)
335-
336-
provider.shutdown()
337-
338-
339211
def test_context_without_targeting_key():
340212
"""Test that FlagEvaluator works with context without targeting key."""
341213
mock_client = Mock()

0 commit comments

Comments
 (0)