Source code for cycletls.exceptions
"""
CycleTLS custom exceptions.
This module provides a hierarchy of exceptions for CycleTLS,
following the pattern established by the requests library.
"""
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from .schema import Response
[docs]
class CycleTLSError(Exception):
"""
Base exception for all CycleTLS errors.
All CycleTLS-specific exceptions inherit from this class,
making it easy to catch any CycleTLS-related error.
"""
pass
[docs]
class RequestException(CycleTLSError):
"""
Base class for all request-related exceptions.
This is the base exception for errors that occur during
the request/response cycle.
"""
pass
[docs]
class HTTPError(RequestException):
"""
An HTTP error occurred (4xx or 5xx status code).
This exception is raised when raise_for_status() is called
on a Response with a 4xx or 5xx status code.
Attributes:
response: The Response object (if available)
"""
def __init__(self, message: str, response: Optional["Response"] = None):
"""
Initialize HTTPError.
Args:
message: Error message
response: Response object that triggered the error
"""
super().__init__(message)
self.response = response
[docs]
class ConnectionError(RequestException):
"""
A connection error occurred.
Raised when a request fails due to network connectivity issues,
such as DNS lookup failures or connection refused errors.
"""
pass
[docs]
class Timeout(RequestException):
"""
The request timed out.
Raised when a request exceeds the specified timeout duration.
This includes both connection timeouts and read timeouts.
"""
pass
[docs]
class TooManyRedirects(RequestException):
"""
Too many redirects occurred.
Raised when the maximum number of redirects is exceeded.
"""
pass
[docs]
class InvalidURL(RequestException):
"""
The URL provided was invalid.
Raised when attempting to make a request with a malformed
or invalid URL.
"""
pass
[docs]
class TLSError(RequestException):
"""
A TLS/SSL error occurred.
Raised when there are issues with TLS/SSL certificates,
protocol version mismatches, or other TLS-related errors.
"""
pass
[docs]
class ProxyError(RequestException):
"""
A proxy error occurred.
Raised when there are issues connecting to or communicating
through a proxy server.
"""
pass
# Aliases for backward compatibility with other HTTP libraries
ConnectTimeout = Timeout
ReadTimeout = Timeout