File size: 1,223 Bytes
ae4e2a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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
        )