Skip to content

Handling httpx exceptions in Application.builder based app #4175

Closed Answered by b-ferd
b-ferd asked this question in Q&A
Discussion options

You must be logged in to vote

Solved itself!
I found this posting 3430 by Bibo-Joshi.
This is the working code snippet, for reference:

def error_callback(error, application):
	application.create_task(application.process_error(update=None, error=error))

async def botloop() -> NoReturn:
	application = Application.builder().token(bot_token).build()
	application.add_handler(CommandHandler("start", start))
	application.add_error_handler(error_handler)
	await application.initialize()
	await application.updater.start_polling(allowed_updates=Update.ALL_TYPES, \
		error_callback=functools.partial(error_callback, application=application))
	await application.start()
	
	while True:
		await asyncio.sleep(1)
	
	# dropped from the …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Bibo-Joshi
Comment options

Answer selected by b-ferd
Comment options

You must be logged in to vote
1 reply
@Bibo-Joshi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants