fix: Added an exception and fixed the returned result on error

This commit is contained in:
Данил 2024-12-22 18:39:55 +03:00
parent d7126e657e
commit 4fd2d3d182

View file

@ -54,22 +54,26 @@ class Converter:
self.conv_amount = float(conv_amount) self.conv_amount = float(conv_amount)
def kekkai(self) -> bool: def kekkai(self) -> bool:
date = datetime.today().strftime('%Y-%m-%d') date = datetime.today().strftime('%Y-%m-%d')
res = requests.get(f'{config['kekkai_instance']}/api/getRate/', { try:
'from_currency': self.from_currency, res = requests.get(f'{config['kekkai_instance']}/api/getRate/', {
'conv_currency': self.conv_currency, 'from_currency': self.from_currency,
'date': date 'conv_currency': self.conv_currency,
}, timeout=3) 'date': date
}, timeout=3)
data = res.json() data = res.json()
if not HTTPStatus(res.status_code).is_success: if not HTTPStatus(res.status_code).is_success:
return None return False
self.conv_amount = float(data.get('rate') * self.amount) self.conv_amount = float(data.get('rate') * self.amount)
return True return True
except requests.exceptions.ConnectionError:
return False