File size: 1,381 Bytes
26574ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import HTTPException, status


class ChatBotError(Exception):
    """Base exception class for chatbot-related errors"""
    pass


class TaskNotFoundError(ChatBotError):
    """Raised when a task is not found"""
    pass


class ConversationNotFoundError(ChatBotError):
    """Raised when a conversation is not found"""
    pass


class AuthenticationError(ChatBotError):
    """Raised when authentication fails"""
    pass


class AuthorizationError(ChatBotError):
    """Raised when user is not authorized to access a resource"""
    pass


class MCPToolError(ChatBotError):
    """Raised when an MCP tool operation fails"""
    pass


def raise_http_exception(status_code: int, detail: str):
    """Utility function to raise HTTP exceptions"""
    raise HTTPException(status_code=status_code, detail=detail)


def raise_not_found(detail: str = "Resource not found"):
    """Utility function to raise a 404 error"""
    raise_http_exception(status_code=status.HTTP_404_NOT_FOUND, detail=detail)


def raise_unauthorized(detail: str = "Not authenticated"):
    """Utility function to raise a 401 error"""
    raise_http_exception(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail)


def raise_forbidden(detail: str = "Access denied"):
    """Utility function to raise a 403 error"""
    raise_http_exception(status_code=status.HTTP_403_FORBIDDEN, detail=detail)