Files
OpenBB/openbb_platform/providers/benzinga/openbb_benzinga/utils/helpers.py
Danglewood 258e158606 [BugFix] Add Exception Handling For Unauthorized API Key Error. (#6800)
* add exception handling for unauthorized api call request.

* linting

* more linting

* more linting

* missed files

* biztoc cassette

* more linting

* crypto interval choices as 7d and 30d instead of 5 and 21

* update the default message and a few Intrinio endpoints to use the unauthorized error.

* mypy

* no-else-raise

---------

Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
2024-10-23 08:26:20 +00:00

25 lines
770 B
Python

"""Benzinga Helpers."""
from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.provider.utils.errors import EmptyDataError, UnauthorizedError
async def response_callback(response, _):
"""Response callback."""
# pylint: disable=import-outside-toplevel
results = await response.json()
if (
results
and isinstance(results, list)
and len(results) == 1
and isinstance(results[0], str)
):
if "access denied" in results[0].lower():
raise UnauthorizedError(f"Unauthorized Benzinga request -> {results[0]}")
raise OpenBBError(results[0])
if isinstance(results, list) and not results:
raise EmptyDataError("The request was returned empty.")
return results