Skip to content

Commit b078f83

Browse files
author
Mikhail Pyrev
committed
Add error handling in token getter
1 parent 36bf703 commit b078f83

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

capitalist/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from cryptography.hazmat.primitives.asymmetric import padding
66
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
77

8-
from .exceptions import RequestException
8+
from .exceptions import RequestException, ResponseException
99
from .utils import retry
1010

1111

@@ -17,13 +17,16 @@ def __init__(self, request_executor, login, password):
1717
self._encrypted_password = None
1818
self._token = None
1919

20-
@retry((RequestException,))
20+
@retry((RequestException, ResponseException))
2121
def _get_token(self):
2222
data = {
2323
'operation': 'get_token',
2424
'login': self.login,
2525
}
2626
json_data = self.request_executor.request(data=data)
27+
code = json_data['code']
28+
if code != 0:
29+
raise ResponseException(code, json_data['message'])
2730
return json_data
2831

2932
def setup(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# For a discussion on single-sourcing the version across setup.py and the
4444
# project code, see
4545
# https://packaging.python.org/en/latest/single_source_version.html
46-
version='1.2.0', # Required
46+
version='1.2.1', # Required
4747

4848
# This is a one-line description or tagline of what your project does. This
4949
# corresponds to the "Summary" metadata field:

0 commit comments

Comments
 (0)