Updated exception hadnling in server to use fastAPI exception handlers, and moved custom exception classes to exception_handler.py in Common
This commit is contained in:
1 parent
5669536c55
commit
5444ee97e3
5 files changed
+247
-101
No files matched your search
@@ -0,0 +1,91 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from aare.common.logger_config import setup_logger
|
||||
|
||||
logger = setup_logger("aareDAQ")
|
||||
|
||||
class TransformationInvalidException(Exception):
|
||||
def __init__(self, message: str = "Transformation is not implemented"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
|
||||
class LoopCenteringFailed(Exception):
|
||||
def __init__(self, message: str = "Loop Centering did not detect a sample"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
|
||||
class MountingFailed(Exception):
|
||||
def __init__(self, message: str = "A sample was not mounted"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
|
||||
class WarningTellException(Exception):
|
||||
def __init__(self, message: str = "Warning error in TELL"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
|
||||
class CriticalTellException(Exception):
|
||||
def __init__(self, message: str = "Critical error in TELL"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
|
||||
class AXCFailed(Exception):
|
||||
def __init__(self, message: str = "Auto X-ray centering failed"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
class BeamlineBusyException(Exception):
|
||||
def __init__(self, message: str = "Beamline is in busy state"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
class SampleException(Exception):
|
||||
def __init__(self, message: str = "Sample not found"):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
class AuthenticationException(Exception):
|
||||
def __init__(self, message: str = "Sample belongs to a different user."):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
Reference in new issue
Block a user