Returning error when archive failed.

This commit is contained in:
Roland 2021-11-10 11:19:07 -07:00
parent 40f493ee68
commit aa1e2f266e
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93

View file

@ -108,22 +108,26 @@ def prepare_bytes(b: bytes) -> str:
@app.post('/json')
async def post_archive(request: Request):
url = request.json['url']
singlefile, screenshot = await asyncio.gather(call_single_file(url), take_screenshot(url))
with tempfile.NamedTemporaryFile('wb') as fh:
fh.write(singlefile)
readability = await extract_readability(fh.name, url)
try:
singlefile, screenshot = await asyncio.gather(call_single_file(url), take_screenshot(url))
with tempfile.NamedTemporaryFile('wb') as fh:
fh.write(singlefile)
readability = await extract_readability(fh.name, url)
# Compress for smaller response.
singlefile = prepare_bytes(singlefile)
screenshot = prepare_bytes(screenshot)
# Compress for smaller response.
singlefile = prepare_bytes(singlefile)
screenshot = prepare_bytes(screenshot)
ret = dict(
url=url,
singlefile=singlefile,
readability=readability,
screenshot=screenshot,
)
return response.json(ret)
ret = dict(
url=url,
singlefile=singlefile,
readability=readability,
screenshot=screenshot,
)
return response.json(ret)
except Exception:
logger.fatal(f'Failed to archive {url}', exc_info=True)
return response.json({'error': f'Failed to archive {url}'})
if __name__ == '__main__':