|
3 | 3 | import json |
4 | 4 | from datetime import datetime |
5 | 5 | from enum import IntEnum |
6 | | -from typing import TYPE_CHECKING, Any, List, Optional |
| 6 | +from typing import TYPE_CHECKING, Any, List, NoReturn, Optional |
7 | 7 |
|
8 | 8 | import requests |
9 | 9 |
|
10 | 10 | from bfxapi._utils.json_decoder import JSONDecoder |
11 | 11 | from bfxapi._utils.json_encoder import JSONEncoder |
12 | 12 | from bfxapi.exceptions import InvalidCredentialError |
13 | | -from bfxapi.rest.exceptions import RequestParametersError, UnknownGenericError |
| 13 | +from bfxapi.rest.exceptions import GenericError, RequestParameterError |
14 | 14 |
|
15 | 15 | if TYPE_CHECKING: |
16 | 16 | from requests.sessions import _Params |
@@ -86,28 +86,30 @@ def post( |
86 | 86 |
|
87 | 87 | return data |
88 | 88 |
|
89 | | - def __handle_error(self, error: List[Any]) -> None: |
| 89 | + def __handle_error(self, error: List[Any]) -> NoReturn: |
90 | 90 | if error[1] == _Error.ERR_PARAMS: |
91 | | - raise RequestParametersError( |
92 | | - "The request was rejected with the following parameter" |
93 | | - f"error: <{error[2]}>" |
| 91 | + raise RequestParameterError( |
| 92 | + "The request was rejected with the following parameter " |
| 93 | + f"error: <{error[2]}>." |
94 | 94 | ) |
95 | 95 |
|
96 | 96 | if error[1] == _Error.ERR_AUTH_FAIL: |
97 | 97 | raise InvalidCredentialError( |
98 | | - "Cannot authenticate with given API-KEY and API-SECRET." |
| 98 | + "Can't authenticate with given API-KEY and API-SECRET." |
99 | 99 | ) |
100 | 100 |
|
101 | 101 | if not error[1] or error[1] == _Error.ERR_UNK or error[1] == _Error.ERR_GENERIC: |
102 | | - raise UnknownGenericError( |
103 | | - "The server replied to the request with a generic error with " |
104 | | - f"the following message: <{error[2]}>." |
| 102 | + raise GenericError( |
| 103 | + "The request was rejected with the following generic " |
| 104 | + f"error: <{error[2]}>." |
105 | 105 | ) |
106 | 106 |
|
| 107 | + raise RuntimeError( |
| 108 | + f"The request was rejected with an unexpected error: <{error}>." |
| 109 | + ) |
| 110 | + |
107 | 111 | def __get_authentication_headers(self, endpoint: str, data: Optional[str] = None): |
108 | | - assert ( |
109 | | - self.__api_key and self.__api_secret |
110 | | - ), "API-KEY and API-SECRET must be strings." |
| 112 | + assert self.__api_key and self.__api_secret |
111 | 113 |
|
112 | 114 | nonce = str(round(datetime.now().timestamp() * 1_000_000)) |
113 | 115 |
|
|
0 commit comments