mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* 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>
25 lines
770 B
Python
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
|