From 780845df58ac9278a18d6cab6c7aa6cb8cc0107a Mon Sep 17 00:00:00 2001 From: odysseusmax Date: Tue, 18 Aug 2020 11:51:18 +0530 Subject: [PATCH] some error handling --- app/views.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/views.py b/app/views.py index eafac1c..a760067 100644 --- a/app/views.py +++ b/app/views.py @@ -126,7 +126,11 @@ class Views: alias_id = req.rel_url.path.split('/')[1] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat_id = chat['chat_id'] - message = await self.client.get_messages(entity=chat_id, ids=file_id) + try: + message = await self.client.get_messages(entity=chat_id, ids=file_id) + except: + log.debug(f"Error in getting message {file_id} in {chat_id}", exc_info=True) + message = None if not message or not isinstance(message, Message): log.debug(f"no valid entry for {file_id} in {chat_id}") return { @@ -195,7 +199,11 @@ class Views: alias_id = req.rel_url.path.split('/')[1] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat_id = chat['chat_id'] - photo = await self.client.get_profile_photos(chat_id) + try: + photo = await self.client.get_profile_photos(chat_id) + except: + log.debug(f"Error in getting profile picture in {chat_id}", exc_info=True) + photo = None if not photo: return web.Response(status=404, text="404: Chat has no profile photo") photo = photo[0] @@ -236,7 +244,11 @@ class Views: alias_id = req.rel_url.path.split('/')[1] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat_id = chat['chat_id'] - message = await self.client.get_messages(entity=chat_id, ids=file_id) + try: + message = await self.client.get_messages(entity=chat_id, ids=file_id) + except: + log.debug(f"Error in getting message {file_id} in {chat_id}", exc_info=True) + message = None if not message or not message.file: log.debug(f"no result for {file_id} in {chat_id}") return web.Response(status=410, text="410: Gone. Access to the target resource is no longer available!")