Source code for macrosynergy.download.exceptions
"""
Custom exceptions for the `macrosynergy.download` subpackage.
"""
import requests
[docs]class ExceptionAdapter(Exception):
"""Base class for all exceptions raised by the macrosynergy package."""
def __init__(self, message: str = ""):
self.message = message
def __str__(self):
# print type and message
return f"{self.__class__.__name__}: {self.message} \n{self.__class__.__name__}"
[docs]class AuthenticationError(ExceptionAdapter):
"""Raised when authentication fails."""
[docs]class DownloadError(ExceptionAdapter):
"""Raised when a download fails or is incomplete."""
[docs]class InvalidResponseError(ExceptionAdapter):
"""Raised when a response is not valid."""
[docs]class HeartbeatError(ExceptionAdapter):
"""Raised when a heartbeat fails."""
[docs]class InvalidDataframeError(ExceptionAdapter):
"""Raised when a dataframe is not valid."""
[docs]class MissingDataError(ExceptionAdapter):
"""Raised when data is missing from a requested dataframe."""
[docs]class NoContentError(ExceptionAdapter):
"""Raised when no data is returned from a request."""
[docs]class DataOutOfSyncError(ExceptionAdapter):
"""Raised when data is out of sync with the expected data."""
KNOWN_EXCEPTIONS = [
requests.exceptions.ConnectionError,
requests.exceptions.ConnectTimeout,
requests.exceptions.ReadTimeout,
ConnectionResetError,
requests.exceptions.Timeout,
requests.exceptions.TooManyRedirects,
requests.exceptions.RequestException,
requests.exceptions.HTTPError,
requests.exceptions.InvalidURL,
requests.exceptions.InvalidSchema,
requests.exceptions.ChunkedEncodingError,
]