Skip to content

Commit 1d8d9fc

Browse files
committed
refactor: avoid duplicate code
Signed-off-by: Federico Bond <[email protected]>
1 parent ee9c31c commit 1d8d9fc

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

openfeature/provider/_registry.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,19 @@ def _initialize_provider(self, provider: FeatureProvider) -> None:
7878
provider, ProviderEvent.PROVIDER_READY, ProviderEventDetails()
7979
)
8080
except Exception as err:
81-
if (
82-
isinstance(err, OpenFeatureError)
83-
and err.error_code == ErrorCode.PROVIDER_FATAL
84-
):
85-
self.dispatch_event(
86-
provider,
87-
ProviderEvent.PROVIDER_ERROR,
88-
ProviderEventDetails(
89-
message=f"Provider initialization failed: {err}",
90-
error_code=ErrorCode.PROVIDER_FATAL,
91-
),
92-
)
93-
else:
94-
self.dispatch_event(
95-
provider,
96-
ProviderEvent.PROVIDER_ERROR,
97-
ProviderEventDetails(
98-
message=f"Provider initialization failed: {err}",
99-
error_code=ErrorCode.GENERAL,
100-
),
101-
)
81+
error_code = (
82+
err.error_code
83+
if isinstance(err, OpenFeatureError)
84+
else ErrorCode.GENERAL
85+
)
86+
self.dispatch_event(
87+
provider,
88+
ProviderEvent.PROVIDER_ERROR,
89+
ProviderEventDetails(
90+
message=f"Provider initialization failed: {err}",
91+
error_code=error_code,
92+
),
93+
)
10294

10395
def _shutdown_provider(self, provider: FeatureProvider) -> None:
10496
try:

0 commit comments

Comments
 (0)