Spaces:
Sleeping
Sleeping
File size: 1,944 Bytes
9f99698 | 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from typing import Optional
from fastapi import HTTPException
class ChatError(HTTPException):
"""Base exception class for chat-related errors"""
def __init__(self, status_code: int, error: str, message: str, detail: Optional[str] = None):
super().__init__(
status_code=status_code,
detail={
"error": error,
"message": message,
"detail": detail
}
)
class InvalidInputError(ChatError):
"""Raised when invalid input is provided to the chat endpoint"""
def __init__(self, message: str = "Invalid input format", detail: Optional[str] = None):
super().__init__(
status_code=400,
error="Invalid input format",
message=message,
detail=detail
)
class UnauthorizedAccessError(ChatError):
"""Raised when user tries to access resources they don't have permission to access"""
def __init__(self, message: str = "Access denied", detail: Optional[str] = None):
super().__init__(
status_code=403,
error="Access denied",
message=message,
detail=detail
)
class ResourceNotFoundError(ChatError):
"""Raised when a requested resource is not found"""
def __init__(self, message: str = "Resource not found", detail: Optional[str] = None):
super().__init__(
status_code=404,
error="Resource not found",
message=message,
detail=detail
)
class ServiceUnavailableError(ChatError):
"""Raised when an external service (like AI service) is unavailable"""
def __init__(self, message: str = "Service temporarily unavailable", detail: Optional[str] = None):
super().__init__(
status_code=503,
error="Service temporarily unavailable",
message=message,
detail=detail
) |