fix: Catch exception when getting redirects on broken capture

pull/537/head
Raphaël Vinot 2022-10-10 14:14:31 +02:00
parent ecf58b512d
commit 63ba82dd0e
1 changed files with 18 additions and 12 deletions

View File

@ -127,7 +127,9 @@ class CaptureRedirects(Resource):
if not cache:
return {'error': 'UUID missing in cache, try again later and check the status first.'}, 400
to_return: Dict[str, Any] = {'response': {'url': cache.url, 'redirects': []}}
to_return: Dict[str, Any] = {}
try:
to_return = {'response': {'url': cache.url, 'redirects': []}}
if not cache.redirects:
to_return['response']['info'] = 'No redirects'
return to_return
@ -139,7 +141,11 @@ class CaptureRedirects(Resource):
to_return['response']['redirects'] = cache.redirects
else:
to_return['response']['redirects'] = cache.redirects
except Exception as e:
if cache and hasattr(cache, 'error'):
to_return['error'] = cache.error
else:
to_return['error'] = str(e)
return to_return