Exceptions for the Twelve Data API

exceptions_twelvedata_api.py: function, exception

This module manages exceptions from Twelve Data API.

exception src.exceptions_twelvedata_api.TwelveDataApiException(code, message)

Bases: Exception

Exception class for issues coming from Twelve Data API.

Examples

>>> try:
...     raise TwelveDataApiException(500, "Erreur")
... except TwelveDataApiException as e:
...     print(e.code, e.message)
500 Erreur
src.exceptions_twelvedata_api.handle_exception(func)

Wrapper for exceptions handling.

This wrapper catch exceptions.

Parameters:

func (function) – Function called within the wrapper.

Examples

Let’s define a simple function that raise TwelveDataApiException if its argument is True :

>>> @handle_exception
... def foo(raise_exception: bool):
...     if raise_exception:
...         raise TwelveDataApiException(500, "Erreur")
...     else:
...         return "Nothing happened"
>>> foo(raise_exception=True)
{'status': 'error', 'code': 500, 'message': 'Erreur'}
>>> foo(raise_exception=False)
'Nothing happened'