From 7e9ba1b437dcf4a1b08060f67e47bf3581d91682 Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 18 Mar 2020 02:36:01 -0400 Subject: [PATCH] Change fetch method to raise AssertionError if response error --- src/utils/scraper.py | 5 +++++ src/utils/utils.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 99780d7..8e3721a 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -49,6 +49,11 @@ async def query_kheina(url): source = re.search('\\d+$', content['results'][0]['sources'][0]['source']).group(0) export = await u.fetch(f'https://faexport.spangle.org.uk/submission/{source}.json', json=True) + try: + export = await u.fetch(f'https://faexport.spangle.org.uk/submission/{submission}.json', json=True) + thumbnail = export['full'] + except AssertionError: + thumbnail = '' result = { 'source': content['results'][0]['sources'][0]['source'], diff --git a/src/utils/utils.py b/src/utils/utils.py index f9ab5ea..17e20a8 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -91,9 +91,9 @@ async def fetch(url, *, post={}, response=False, text=False, json=False): if post: async with asession.post(url, data=post, headers={ 'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r: - if r.status != 200: - return r.status - elif response: + assert r.status == 200 + + if response: return r elif text: return await r.text()