Drop modules bfxapi.enums, bfxapi.rest.enums and bfxapi.websocket.enums.

This commit is contained in:
Davide Casale
2023-10-26 05:41:47 +02:00
parent 8e915e42eb
commit 2734ff9e1a
13 changed files with 50 additions and 159 deletions

View File

@@ -1,10 +1,11 @@
from typing import TYPE_CHECKING, Optional, Any
from enum import Enum
from http import HTTPStatus
import time, hmac, hashlib, json, requests
from ..enums import Error
from ..exceptions import ResourceNotFound, RequestParametersError, InvalidCredentialError, UnknownGenericError
from ..._utils.json_encoder import JSONEncoder
from ..._utils.json_decoder import JSONDecoder
@@ -12,6 +13,12 @@ from ..._utils.json_decoder import JSONDecoder
if TYPE_CHECKING:
from requests.sessions import _Params
class _Error(Enum):
ERR_UNK = 10000
ERR_GENERIC = 10001
ERR_PARAMS = 10020
ERR_AUTH_FAIL = 10100
class Middleware:
TIMEOUT = 30
@@ -53,11 +60,11 @@ class Middleware:
data = response.json(cls=JSONDecoder)
if len(data) and data[0] == "error":
if data[1] == Error.ERR_PARAMS:
if data[1] == _Error.ERR_PARAMS:
raise RequestParametersError("The request was rejected with the " \
f"following parameter error: <{data[2]}>")
if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
if data[1] is None or data[1] == _Error.ERR_UNK or data[1] == _Error.ERR_GENERIC:
raise UnknownGenericError("The server replied to the request with " \
f"a generic error with message: <{data[2]}>.")
@@ -86,14 +93,14 @@ class Middleware:
data = response.json(cls=JSONDecoder)
if isinstance(data, list) and len(data) and data[0] == "error":
if data[1] == Error.ERR_PARAMS:
if data[1] == _Error.ERR_PARAMS:
raise RequestParametersError("The request was rejected with the " \
f"following parameter error: <{data[2]}>")
if data[1] == Error.ERR_AUTH_FAIL:
if data[1] == _Error.ERR_AUTH_FAIL:
raise InvalidCredentialError("Cannot authenticate with given API-KEY and API-SECRET.")
if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
if data[1] is None or data[1] == _Error.ERR_UNK or data[1] == _Error.ERR_GENERIC:
raise UnknownGenericError("The server replied to the request with " \
f"a generic error with message: <{data[2]}>.")