mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-01 08:01:22 +03:00
Simplified if ladder
Removed a large if ladder with a simpler construct that does the same thing
This commit is contained in:
parent
31e0758ee4
commit
9363b1457d
31
companion.py
31
companion.py
@ -236,20 +236,10 @@ class Auth(object):
|
|||||||
|
|
||||||
if not data.get('code'):
|
if not data.get('code'):
|
||||||
print('Auth\tNegative response {!r}'.format(payload))
|
print('Auth\tNegative response {!r}'.format(payload))
|
||||||
|
error = next(
|
||||||
# TODO(A_D): there should be a cleaner way to do this rather than raising in every if
|
(data[k] for k in ('error_description', 'error', 'message') if k in data), ('<unknown error>',)
|
||||||
# Additionally, this is basically the same code as seen below, helper method perhaps?
|
)
|
||||||
if data.get('error_description'):
|
raise CredentialsError('Error: {!r}'.format(error)[0])
|
||||||
raise CredentialsError('Error: {!r}'.format(data['error_description'][0]))
|
|
||||||
|
|
||||||
elif data.get('error'):
|
|
||||||
raise CredentialsError('Error: {!r}'.format(data['error'][0]))
|
|
||||||
|
|
||||||
elif data.get('message'):
|
|
||||||
raise CredentialsError('Error: {!r}'.format(data['message'][0]))
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise CredentialsError()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = None
|
r = None
|
||||||
@ -285,17 +275,8 @@ class Auth(object):
|
|||||||
|
|
||||||
print('Auth\tCan\'t get token for {}'.format(self.cmdr))
|
print('Auth\tCan\'t get token for {}'.format(self.cmdr))
|
||||||
self.dump(r)
|
self.dump(r)
|
||||||
if data.get('error_description'):
|
error = next((data[k] for k in ('error_description', 'error', 'message') if k in data), ('<unknown error>',))
|
||||||
raise CredentialsError('Error: {!r}'.format(data['error_description']))
|
raise CredentialsError('Error: {!r}'.format(error)[0])
|
||||||
|
|
||||||
elif data.get('error'):
|
|
||||||
raise CredentialsError('Error: {!r}'.format(data['error']))
|
|
||||||
|
|
||||||
elif data.get('message'):
|
|
||||||
raise CredentialsError('Error: {!r}'.format(data['message']))
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise CredentialsError()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def invalidate(cmdr):
|
def invalidate(cmdr):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user