-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathexceptions.py
87 lines (72 loc) · 3.02 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from open_feature.flag_evaluation.error_code import ErrorCode
class OpenFeatureError(Exception):
"""
A generic open feature exception, this exception should not be raised. Instead
the more specific exceptions extending this one should be used.
"""
def __init__(self, error_message: str = None, error_code: ErrorCode = None):
"""
Constructor for the generic OpenFeatureError.
@param error_message: a string message representing why the error has been
raised
@param error_code: the ErrorCode string enum value for the type of error
@return: the generic OpenFeatureError exception
"""
self.error_message = error_message
self.error_code = error_code
class FlagNotFoundError(OpenFeatureError):
"""
This exception should be raised when the provider cannot find a flag with the
key provided by the user.
"""
def __init__(self, error_message: str = None):
"""
Constructor for the FlagNotFoundError. The error code for
this type of exception is ErrorCode.FLAG_NOT_FOUND.
@param error_message: a string message representing why the error has been
raised
@return: the generic FlagNotFoundError exception
"""
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
class GeneralError(OpenFeatureError):
"""
This exception should be raised when the for an exception within the open
feature python sdk.
"""
def __init__(self, error_message: str = None):
"""
Constructor for the GeneralError. The error code for this type of exception
is ErrorCode.GENERAL.
@param error_message: a string message representing why the error has been
raised
@return: the generic GeneralError exception
"""
super().__init__(error_message, ErrorCode.GENERAL)
class ParseError(OpenFeatureError):
"""
This exception should be raised when the flag returned by the provider cannot
be parsed into a FlagEvaluationDetails object.
"""
def __init__(self, error_message: str = None):
"""
Constructor for the ParseError. The error code for this type of exception
is ErrorCode.PARSE_ERROR.
@param error_message: a string message representing why the error has been
raised
@return: the generic ParseError exception
"""
super().__init__(error_message, ErrorCode.PARSE_ERROR)
class TypeMismatchError(OpenFeatureError):
"""
This exception should be raised when the flag returned by the provider does
not match the type requested by the user.
"""
def __init__(self, error_message: str = None):
"""
Constructor for the TypeMismatchError. The error code for this type of
exception is ErrorCode.TYPE_MISMATCH.
@param error_message: a string message representing why the error has been
raised
@return: the generic TypeMismatchError exception
"""
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)