mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 14:47:29 +00:00
Change fetch method to raise AssertionError if response error
This commit is contained in:
parent
a6431ca4c3
commit
7e9ba1b437
2 changed files with 8 additions and 3 deletions
|
@ -49,6 +49,11 @@ async def query_kheina(url):
|
||||||
|
|
||||||
source = re.search('\\d+$', content['results'][0]['sources'][0]['source']).group(0)
|
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)
|
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 = {
|
result = {
|
||||||
'source': content['results'][0]['sources'][0]['source'],
|
'source': content['results'][0]['sources'][0]['source'],
|
||||||
|
|
|
@ -91,9 +91,9 @@ async def fetch(url, *, post={}, response=False, text=False, json=False):
|
||||||
if post:
|
if post:
|
||||||
async with asession.post(url, data=post, headers={
|
async with asession.post(url, data=post, headers={
|
||||||
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
|
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
|
||||||
if r.status != 200:
|
assert r.status == 200
|
||||||
return r.status
|
|
||||||
elif response:
|
if response:
|
||||||
return r
|
return r
|
||||||
elif text:
|
elif text:
|
||||||
return await r.text()
|
return await r.text()
|
||||||
|
|
Loading…
Reference in a new issue