Fix formatting issue with handling exception on image error

This commit is contained in:
Frisk 2021-01-12 17:49:56 +01:00
parent 427289a9bc
commit 327bc60c03
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC

View file

@ -5,6 +5,7 @@ import time
import json import json
import logging import logging
import datetime import datetime
from aiohttp import ClientResponseError
from src.config import settings from src.config import settings
from src.misc import link_formatter, create_article_path, parse_link, profile_field_name, ContentParser from src.misc import link_formatter, create_article_path, parse_link, profile_field_name, ContentParser
from src.discord import DiscordMessage from src.discord import DiscordMessage
@ -653,9 +654,14 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
logger.warning("Unable to download data on the edit content!") logger.warning("Unable to download data on the edit content!")
elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files elif action in ("upload/overwrite", "upload/upload", "upload/revert"): # sending files
license = None license = None
urls = await recent_changes.safe_request( try:
urls = await recent_changes.safe_request(
"{wiki}?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl%7Carchivename&iilimit=5".format( "{wiki}?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl%7Carchivename&iilimit=5".format(
wiki=WIKI_API_PATH, filename=change["title"]), rate_limiter, "query", "pages") wiki=WIKI_API_PATH, filename=change["title"]), rate_limiter, "query", "pages")
except ClientResponseError:
# We could do this in safe_request but I don't know how that would affect other requests,
# prefer to have handling in here instead. When this happens, simply ignore the image preview
urls = None
link = create_article_path(change["title"], WIKI_ARTICLE_PATH) link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
additional_info_retrieved = False additional_info_retrieved = False
if urls is not None: if urls is not None: