Skip to content

Exceptions

This page contains the reference for all custom exceptions.

Handling Errors

All exceptions raised by seedrcc inherit from the base exception seedrcc.exceptions.SeedrError. This allows you to catch all errors from the library with a single try...except block, while still being able to handle specific error types differently.

Here is a example of how you can handle various exceptions:

import seedrcc

try:
    # This operation might fail for various reasons
    client.add_torrent("some-magnet-link")

except seedrcc.exceptions.APIError as e:
    # Handle specific API errors (e.g., invalid magnet)
    print(f"An API error occurred: {e}")
    print(f"Error Type: {e.error_type}, Code: {e.code}")

except seedrcc.exceptions.AuthenticationError as e:
    # Handle authentication failures (e.g., invalid token)
    print(f"An authentication error occurred: {e}")

except seedrcc.exceptions.SeedrError as e:
    # Catch any other library-specific errors
    print(f"An unexpected error occurred with seedrcc: {e}")

Exception Reference

seedrcc.exceptions

SeedrError

Bases: Exception

Base exception for all seedrcc errors.

Source code in seedrcc/exceptions.py
7
8
class SeedrError(Exception):
    """Base exception for all seedrcc errors."""

APIError

Bases: SeedrError

Raised when the API returns an error.

Attributes:

Name Type Description
response Optional[Response]

The full HTTP response object.

code Optional[int]

The custom error code from the API response body.

error_type Optional[str]

The type of error from the API response body (e.g., 'parsing_error').

Source code in seedrcc/exceptions.py
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
class APIError(SeedrError):
    """
    Raised when the API returns an error.

    Attributes:
        response (Optional[httpx.Response]): The full HTTP response object.
        code (Optional[int]): The custom error code from the API response body.
        error_type (Optional[str]): The type of error from the API response body (e.g., 'parsing_error').
    """

    def __init__(
        self, default_message: str = "An API error occurred.", response: Optional[httpx.Response] = None
    ) -> None:
        self.response = response
        self.code: Optional[int] = None
        self.error_type: Optional[str] = None

        if response:
            try:
                data = response.json()
                if isinstance(data, dict):
                    self.code = data.get("code")
                    self.error_type = data.get("result")
                    default_message = data.get("error") or default_message

            except json.JSONDecodeError:
                pass

        super().__init__(default_message)

ServerError

Bases: SeedrError

Raised for 5xx server-side errors.

Source code in seedrcc/exceptions.py
42
43
44
45
46
47
48
49
50
51
52
53
class ServerError(SeedrError):
    """Raised for 5xx server-side errors."""

    def __init__(
        self, default_message: str = "A server error occurred.", response: Optional[httpx.Response] = None
    ) -> None:
        self.response = response
        if response:
            message = f"{response.status_code} {response.reason_phrase}"
        else:
            message = default_message
        super().__init__(message)

AuthenticationError

Bases: SeedrError

Raised when authentication or re-authentication fails.

Attributes:

Name Type Description
response Optional[Response]

The full HTTP response object from the failed auth attempt.

error_type Optional[str]

The error type from the API response body (e.g., 'invalid_grant').

Source code in seedrcc/exceptions.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class AuthenticationError(SeedrError):
    """
    Raised when authentication or re-authentication fails.

    Attributes:
        response (Optional[httpx.Response]): The full HTTP response object from the failed auth attempt.
        error_type (Optional[str]): The error type from the API response body (e.g., 'invalid_grant').
    """

    def __init__(
        self, default_message: str = "An authentication error occurred.", response: Optional[httpx.Response] = None
    ) -> None:
        self.response = response
        self.error_type: Optional[str] = None
        message = default_message

        # Attempt to parse a more specific error message from the response
        if response:
            try:
                data = response.json()
                if isinstance(data, dict):
                    # Use 'error_description' as the main message if available
                    if "error_description" in data:
                        message = data["error_description"]
                    self.error_type = data.get("error")
            except json.JSONDecodeError:
                pass

        super().__init__(message)

NetworkError

Bases: SeedrError

Raised for network-level errors, such as timeouts or connection problems.

Source code in seedrcc/exceptions.py
87
88
89
90
class NetworkError(SeedrError):
    """Raised for network-level errors, such as timeouts or connection problems."""

    pass

TokenError

Bases: SeedrError

Raised for errors related to token serialization or deserialization.

Source code in seedrcc/exceptions.py
93
94
95
96
class TokenError(SeedrError):
    """Raised for errors related to token serialization or deserialization."""

    pass