Skip to content

Commit

Permalink
Merge pull request #1251 from smilerz/fail_connection_gracefully
Browse files Browse the repository at this point in the history
ConnectError fail gracefully during URL import
  • Loading branch information
vabene1111 authored Jan 7, 2022
2 parents 1f391b7 + b09acef commit 6c4b1e7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,16 @@ def recipe_from_source(request):
return JsonResponse({"recipe_json": get_from_scraper(scrape, request)})
elif (mode == 'source') or (mode == 'url' and auto == 'false'):
if not data or data == 'undefined':
data = requests.get(url, headers=HEADERS).content
try:
data = requests.get(url, headers=HEADERS).content
except requests.exceptions.ConnectionError:
return JsonResponse(
{
'error': True,
'msg': _('Connection Refused.')
},
status=400
)
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(data, url, request)
if len(recipe_tree) == 0 and len(recipe_json) == 0:
return JsonResponse(
Expand Down

0 comments on commit 6c4b1e7

Please sign in to comment.