File size: 2,050 Bytes
3d83b62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
"""Custom exceptions for CiteScan."""


class CiteScanException(Exception):
    """Base exception for CiteScan."""

    def __init__(self, message: str, details: dict | None = None):
        """Initialize exception.

        Args:
            message: Error message
            details: Optional additional details
        """
        self.message = message
        self.details = details or {}
        super().__init__(self.message)


class FetcherException(CiteScanException):
    """Exception raised by fetchers."""

    def __init__(self, message: str, source: str, details: dict | None = None):
        """Initialize fetcher exception.

        Args:
            message: Error message
            source: Fetcher source (e.g., 'arxiv', 'crossref')
            details: Optional additional details
        """
        self.source = source
        super().__init__(message, details)


class ParserException(CiteScanException):
    """Exception raised by parsers."""

    pass


class ValidationException(CiteScanException):
    """Exception raised during validation."""

    pass


class RateLimitException(FetcherException):
    """Exception raised when rate limit is exceeded."""

    def __init__(self, source: str, retry_after: int | None = None):
        """Initialize rate limit exception.

        Args:
            source: Fetcher source
            retry_after: Seconds to wait before retry
        """
        self.retry_after = retry_after
        message = f"Rate limit exceeded for {source}"
        if retry_after:
            message += f". Retry after {retry_after} seconds"
        super().__init__(message, source)


class TimeoutException(FetcherException):
    """Exception raised when request times out."""

    def __init__(self, source: str, timeout: int):
        """Initialize timeout exception.

        Args:
            source: Fetcher source
            timeout: Timeout value in seconds
        """
        message = f"Request to {source} timed out after {timeout} seconds"
        super().__init__(message, source)