""" Custom Exceptions ================= Application-specific exceptions """ from fastapi import HTTPException, status class ToxicDetectionException(HTTPException): """Base exception for toxic detection""" def __init__(self, detail: str, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR): super().__init__(status_code=status_code, detail=detail) class ModelNotLoadedException(ToxicDetectionException): """Raised when model is not loaded""" def __init__(self): super().__init__( detail="Model not loaded. Please check server logs.", status_code=status.HTTP_503_SERVICE_UNAVAILABLE ) class InvalidTextException(ToxicDetectionException): """Raised when input text is invalid""" def __init__(self, detail: str = "Invalid text input"): super().__init__( detail=detail, status_code=status.HTTP_400_BAD_REQUEST ) class AnalysisException(ToxicDetectionException): """Raised when analysis fails""" def __init__(self, detail: str = "Analysis failed"): super().__init__( detail=detail, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR )