diff --git a/bfxapi/_client.py b/bfxapi/_client.py index baf81c6..2a7d8f0 100644 --- a/bfxapi/_client.py +++ b/bfxapi/_client.py @@ -3,10 +3,9 @@ from typing import \ from bfxapi._utils.logging import ColorLogger -from bfxapi._exceptions import IncompleteCredentialError - from bfxapi.rest import BfxRestInterface from bfxapi.websocket import BfxWebSocketClient +from bfxapi.exceptions import IncompleteCredentialError if TYPE_CHECKING: from bfxapi.websocket._client.bfx_websocket_client import \ diff --git a/bfxapi/_exceptions.py b/bfxapi/_exceptions.py deleted file mode 100644 index e408bd6..0000000 --- a/bfxapi/_exceptions.py +++ /dev/null @@ -1,14 +0,0 @@ -class BfxBaseException(Exception): - """ - Base class for every custom exception in bfxapi/rest/exceptions.py and bfxapi/websocket/exceptions.py. - """ - -class IncompleteCredentialError(BfxBaseException): - """ - This error indicates an incomplete credential object (missing api-key or api-secret). - """ - -class InvalidCredentialError(BfxBaseException): - """ - This error indicates that the user has provided incorrect credentials (API-KEY and API-SECRET) for authentication. - """ diff --git a/bfxapi/exceptions.py b/bfxapi/exceptions.py new file mode 100644 index 0000000..663752a --- /dev/null +++ b/bfxapi/exceptions.py @@ -0,0 +1,10 @@ +class BfxBaseException(Exception): + """ + Base class for every custom exception thrown by bitfinex-api-py. + """ + +class IncompleteCredentialError(BfxBaseException): + pass + +class InvalidCredentialError(BfxBaseException): + pass diff --git a/bfxapi/rest/exceptions.py b/bfxapi/rest/exceptions.py index ab7001c..2906fcd 100644 --- a/bfxapi/rest/exceptions.py +++ b/bfxapi/rest/exceptions.py @@ -1,17 +1,10 @@ -# pylint: disable-next=wildcard-import,unused-wildcard-import -from bfxapi._exceptions import * +from bfxapi.exceptions import BfxBaseException -class ResourceNotFound(BfxBaseException): - """ - This error indicates a failed HTTP request to a non-existent resource. - """ +class NotFoundError(BfxBaseException): + pass class RequestParametersError(BfxBaseException): - """ - This error indicates that there are some invalid parameters sent along with an HTTP request. - """ + pass class UnknownGenericError(BfxBaseException): - """ - This error indicates an undefined problem processing an HTTP request sent to the APIs. - """ + pass diff --git a/bfxapi/rest/middleware/middleware.py b/bfxapi/rest/middleware/middleware.py index 4d29418..f279f30 100644 --- a/bfxapi/rest/middleware/middleware.py +++ b/bfxapi/rest/middleware/middleware.py @@ -6,7 +6,9 @@ from http import HTTPStatus import time, hmac, hashlib, json, requests -from ..exceptions import ResourceNotFound, RequestParametersError, InvalidCredentialError, UnknownGenericError +from ..exceptions import NotFoundError, RequestParametersError, UnknownGenericError + +from ...exceptions import InvalidCredentialError from ..._utils.json_encoder import JSONEncoder from ..._utils.json_decoder import JSONDecoder @@ -55,7 +57,7 @@ class Middleware: ) if response.status_code == HTTPStatus.NOT_FOUND: - raise ResourceNotFound(f"No resources found at endpoint <{endpoint}>.") + raise NotFoundError(f"No resources found at endpoint <{endpoint}>.") data = response.json(cls=JSONDecoder) @@ -88,7 +90,7 @@ class Middleware: ) if response.status_code == HTTPStatus.NOT_FOUND: - raise ResourceNotFound(f"No resources found at endpoint <{endpoint}>.") + raise NotFoundError(f"No resources found at endpoint <{endpoint}>.") data = response.json(cls=JSONDecoder) diff --git a/bfxapi/websocket/_client/bfx_websocket_client.py b/bfxapi/websocket/_client/bfx_websocket_client.py index eb7d9ab..df6e8d5 100644 --- a/bfxapi/websocket/_client/bfx_websocket_client.py +++ b/bfxapi/websocket/_client/bfx_websocket_client.py @@ -24,8 +24,10 @@ from bfxapi.websocket._connection import Connection from bfxapi.websocket._handlers import AuthEventsHandler from bfxapi.websocket._event_emitter import BfxEventEmitter +from bfxapi.exceptions import \ + InvalidCredentialError + from bfxapi.websocket.exceptions import \ - InvalidCredentialError, \ ReconnectionTimeoutError, \ VersionMismatchError, \ UnknownChannelError, \ diff --git a/bfxapi/websocket/exceptions.py b/bfxapi/websocket/exceptions.py index e662cbf..fc9aae8 100644 --- a/bfxapi/websocket/exceptions.py +++ b/bfxapi/websocket/exceptions.py @@ -1,47 +1,25 @@ -# pylint: disable-next=wildcard-import,unused-wildcard-import -from bfxapi._exceptions import * +from bfxapi.exceptions import BfxBaseException class ConnectionNotOpen(BfxBaseException): - """ - This error indicates an attempt to communicate via websocket before starting the connection with the servers. - """ - -class FullBucketError(BfxBaseException): - """ - Thrown when a user attempts a subscription but all buckets are full. - """ - -class ReconnectionTimeoutError(BfxBaseException): - """ - This error indicates that the connection has been offline for too long without being able to reconnect. - """ + pass class ActionRequiresAuthentication(BfxBaseException): - """ - This error indicates an attempt to access a protected resource without logging in first. - """ + pass -class UnknownChannelError(BfxBaseException): - """ - Thrown when a user attempts to subscribe to an unknown channel. - """ - -class UnknownSubscriptionError(BfxBaseException): - """ - Thrown when a user attempts to reference an unknown subscription. - """ - -class UnknownEventError(BfxBaseException): - """ - Thrown when a user attempts to add a listener for an unknown event. - """ +class ReconnectionTimeoutError(BfxBaseException): + pass class VersionMismatchError(BfxBaseException): - """ - This error indicates a mismatch between the client version and the server WSS version. - """ + pass class SubIdError(BfxBaseException): - """ - Thrown when a user attempts to open more than one subscription using the same sub_id. - """ + pass + +class UnknownChannelError(BfxBaseException): + pass + +class UnknownEventError(BfxBaseException): + pass + +class UnknownSubscriptionError(BfxBaseException): + pass