mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-09 08:08:24 -05:00
Merge pull request #1251 from smilerz/fail_connection_gracefully
ConnectError fail gracefully during URL import
This commit is contained in:
@@ -1025,7 +1025,16 @@ def recipe_from_source(request):
|
|||||||
return JsonResponse({"recipe_json": get_from_scraper(scrape, request)})
|
return JsonResponse({"recipe_json": get_from_scraper(scrape, request)})
|
||||||
elif (mode == 'source') or (mode == 'url' and auto == 'false'):
|
elif (mode == 'source') or (mode == 'url' and auto == 'false'):
|
||||||
if not data or data == 'undefined':
|
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)
|
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(data, url, request)
|
||||||
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
|
|||||||
Reference in New Issue
Block a user