1010
1111class VMException (Exception ):
1212 """Base exception for VM operations"""
13+
1314 def __init__ (self , message : str , status_code : int = 500 ):
1415 self .message = message
1516 self .status_code = status_code
@@ -18,6 +19,7 @@ def __init__(self, message: str, status_code: int = 500):
1819
1920class VMNotFoundException (VMException ):
2021 """Exception raised when VM is not found"""
22+
2123 def __init__ (self , vm_id : UUID ):
2224 message = f"VM with ID { vm_id } not found"
2325 super ().__init__ (message , status_code = 404 )
@@ -26,6 +28,7 @@ def __init__(self, vm_id: UUID):
2628
2729class InvalidStateTransitionException (VMException ):
2830 """Exception raised when attempting an invalid state transition"""
31+
2932 def __init__ (self , vm_id : UUID , current_state : str , attempted_action : str ):
3033 message = (
3134 f"Cannot perform '{ attempted_action } ' on VM { vm_id } "
@@ -39,13 +42,15 @@ def __init__(self, vm_id: UUID, current_state: str, attempted_action: str):
3942
4043class ValidationException (VMException ):
4144 """Exception raised for validation errors"""
45+
4246 def __init__ (self , message : str , field : Optional [str ] = None ):
4347 super ().__init__ (message , status_code = 422 )
4448 self .field = field
4549
4650
4751class VMAlreadyExistsException (VMException ):
4852 """Exception raised when trying to create a VM with a name that already exists"""
53+
4954 def __init__ (self , name : str ):
5055 message = f"VM with name '{ name } ' already exists"
5156 super ().__init__ (message , status_code = 409 )
0 commit comments