Bases: RequestException
Exception representing a failure to retrieve Scryfall data.
Source code in src\utils\scryfall.py
| class ScryfallException(RequestException):
"""Exception representing a failure to retrieve Scryfall data."""
def __init__(self, **kwargs):
"""Allow details relating to the exception to be passed.
Keyword Args:
exception (Exception): Caught exception to pull potential request details from.
card_name (str): Name of a card.
card_set (str): Set code of a card.
card_number (str): Collector number of a card.
lang (str): Language of a card.
"""
# Check for our kwargs
e = kwargs.pop('exception', None)
params = {
'Name': kwargs.pop('card_name', None),
'Set': kwargs.pop('card_set', None),
'Num': kwargs.pop('card_number', None),
'Lang': kwargs.pop('lang', None)
}
# Compile error message
msg = 'Scryfall request failed!'
if any(params.values()):
# List the params provided
msg += f'\nParams: '
p = [f"{k}: '{v}'" for k, v in params.items() if v]
msg += ', '.join(p)
if e and isinstance(e, RequestException) and e.request:
# Provide the URL which failed
msg += f'\nAPI URL: {e.request.url}'
if e and isinstance(e, Exception):
# Provide the exception cause
msg += f'\nReason: {str(e)}'
super().__init__(msg)
|