feat: add custom exception for missing environment variables
This commit is contained in:
parent
2cc01e1b2f
commit
76c1a2b67f
@ -6,6 +6,10 @@ import json
|
||||
|
||||
NO_DEFAULT = object() # Used to indicate no default value was provided
|
||||
|
||||
class EnviromentKeyMissing(Exception):
|
||||
def __init__(self, key: str):
|
||||
super().__init__(f"Environment variable '{key}' not found.")
|
||||
|
||||
class Modes(Enum):
|
||||
"""
|
||||
Enum for different environment modes.
|
||||
@ -107,8 +111,8 @@ class Environment:
|
||||
If a cast function is provided, it applies the cast to the value before returning.
|
||||
"""
|
||||
|
||||
if default is NO_DEFAULT:
|
||||
return cast(self.__values.get(key))
|
||||
if default is NO_DEFAULT and key not in self.__values:
|
||||
raise EnviromentKeyMissing(key)
|
||||
|
||||
return cast(self.__values.get(key, default))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user