mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
catch TelegramError (fixes #113)
This commit is contained in:
parent
77887d6fbc
commit
59d04d1d0c
|
@ -8,7 +8,7 @@ from tabulate import tabulate
|
|||
import arrow
|
||||
from sqlalchemy import and_, func, text
|
||||
from telegram import ParseMode, Bot, Update
|
||||
from telegram.error import NetworkError
|
||||
from telegram.error import NetworkError, TelegramError
|
||||
from telegram.ext import CommandHandler, Updater
|
||||
|
||||
from freqtrade import exchange, __version__
|
||||
|
@ -475,13 +475,17 @@ def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDO
|
|||
return
|
||||
|
||||
bot = bot or _UPDATER.bot
|
||||
|
||||
try:
|
||||
try:
|
||||
bot.send_message(_CONF['telegram']['chat_id'], msg, parse_mode=parse_mode)
|
||||
except NetworkError as error:
|
||||
except NetworkError as network_err:
|
||||
# Sometimes the telegram server resets the current connection,
|
||||
# if this is the case we send the message again.
|
||||
logger.warning(
|
||||
'Got Telegram NetworkError: %s! Trying one more time.',
|
||||
error.message
|
||||
network_err.message
|
||||
)
|
||||
bot.send_message(_CONF['telegram']['chat_id'], msg, parse_mode=parse_mode)
|
||||
except TelegramError as telegram_err:
|
||||
logger.warning('Got TelegramError: %s! Giving up on that message.', telegram_err.message)
|
||||
|
|
|
@ -535,7 +535,6 @@ def test_send_msg_network_error(default_conf, mocker):
|
|||
default_conf['telegram']['enabled'] = True
|
||||
bot = MagicMock()
|
||||
bot.send_message = MagicMock(side_effect=NetworkError('Oh snap'))
|
||||
with pytest.raises(NetworkError, match=r'Oh snap'):
|
||||
send_msg('test', bot)
|
||||
|
||||
# Bot should've tried to send it twice
|
||||
|
|
Loading…
Reference in New Issue
Block a user