python-sdk: Move exceptions to a single file

This commit is contained in:
Andrew Helsby 2022-06-16 14:47:30 +04:00
parent bee4d214aa
commit b7b675aca6
8 changed files with 37 additions and 44 deletions

View File

@ -1 +0,0 @@
FLAGSMITH_ENVIRONMENT_KEY=""

View File

@ -0,0 +1,29 @@
from src.flag_evaluation.error_code import ErrorCode
class OpenFeatureError(Exception):
def __init__(
self, error_message: str = None, error_code: ErrorCode = None
):
self.error_message = error_message
self.error_code = error_code
class FlagNotFoundError(OpenFeatureError):
def __init__(self, error_message: str = None):
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
class GeneralError(OpenFeatureError):
def __init__(self, error_message: str = None):
super().__init__(error_message, ErrorCode.GENERAL)
class ParseError(OpenFeatureError):
def __init__(self, error_message: str = None):
super().__init__(error_message, ErrorCode.PARSE_ERROR)
class TypeMismatchError(OpenFeatureError):
def __init__(self, error_message: str = None):
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)

View File

@ -1,8 +0,0 @@
from src.exception.open_feature_error import OpenFeatureError
from src.flag_evaluation.error_code import ErrorCode
class FlagNotFoundError(OpenFeatureError):
def __init__(self, error_message: str = None):
self.error_message = error_message
self.error_code = ErrorCode.FLAG_NOT_FOUND

View File

@ -1,8 +0,0 @@
from src.exception.open_feature_error import OpenFeatureError
from src.flag_evaluation.error_code import ErrorCode
class GeneralError(OpenFeatureError):
def __init__(self, error_message: str = None):
self.error_message = error_message
self.error_code = ErrorCode.GENERAL

View File

@ -1,9 +0,0 @@
from src.flag_evaluation.error_code import ErrorCode
class OpenFeatureError(Exception):
def __init__(
self, error_message: str = None, error_code: ErrorCode = None
):
self.error_message = error_message
self.error_code = error_code

View File

@ -1,8 +0,0 @@
from src.exception.open_feature_error import OpenFeatureError
from src.flag_evaluation.error_code import ErrorCode
class ParseError(OpenFeatureError):
def __init__(self, error_message: str = None):
self.error_message = error_message
self.error_code = ErrorCode.PARSE_ERROR

View File

@ -1,8 +0,0 @@
from src.exception.open_feature_error import OpenFeatureError
from src.flag_evaluation.error_code import ErrorCode
class TypeMismatchError(OpenFeatureError):
def __init__(self, error_message: str = None):
self.error_message = error_message
self.error_code = ErrorCode.TYPE_MISMATCH

View File

@ -8,10 +8,16 @@ class OpenFeatureAPI:
def __init__(self):
pass
@staticmethod
def get_client(
self, name: str = None, version: str = None
name: str = None, version: str = None, provider=None
) -> OpenFeatureClient:
open_feature_provider = self.get_provider()
if provider is None:
open_feature_provider = OpenFeatureAPI.get_provider()
else:
OpenFeatureAPI.set_provider(provider)
open_feature_provider = provider
return OpenFeatureClient(
name=name, version=version, provider=open_feature_provider
)