From 5ea353d8c9b52a9e678c691f571c1567bfafc287 Mon Sep 17 00:00:00 2001 From: "hikari.ftg" Date: Mon, 28 Mar 2022 09:43:57 +0000 Subject: [PATCH] Automatically switch to the next photo without showing warning if fetch error occurred --- hikka/inline/gallery.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hikka/inline/gallery.py b/hikka/inline/gallery.py index 519cf9b..6a18fac 100644 --- a/hikka/inline/gallery.py +++ b/hikka/inline/gallery.py @@ -10,6 +10,8 @@ from aiogram.types import ( InlineQuery, ) +from aiogram.utils.exceptions import InvalidHTTPUrlContent, BadRequest + from typing import Union, List from types import FunctionType from telethon.tl.types import Message @@ -335,10 +337,16 @@ class Gallery(InlineUnit): ), reply_markup=self._gallery_markup(btn_call_data), ) + except (InvalidHTTPUrlContent, BadRequest): + logger.warning("Error fetching photo content, attempting load next one") + del self._galleries[gallery_uid]["photos"][ + self._galleries[gallery_uid]["current_index"] + ] + self._galleries[gallery_uid]["current_index"] -= 1 + await self._gallery_next(call, btn_call_data, func, gallery_uid) except Exception: logger.exception("Exception while trying to edit media") await call.answer("Error occurred", show_alert=True) - return def _get_next_photo(self, gallery_uid: str) -> str: """Returns next photo"""