0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Refactor try-catch block by limiting code in the try block

Always good to know which line will raise an exception and limit the try block to that statement
This commit is contained in:
Ann Paul 2015-10-02 23:17:49 -07:00
parent 1a51609701
commit 1b7a3f045b

View File

@ -31,15 +31,14 @@ class ImageEmbedHandler(object):
Image = get_image_model()
try:
image = Image.objects.get(id=attrs['id'])
image_format = get_image_format(attrs['format'])
if for_editor:
try:
return image_format.image_to_editor_html(image, attrs['alt'])
except:
return ''
else:
return image_format.image_to_html(image, attrs['alt'])
except Image.DoesNotExist:
return "<img>"
image_format = get_image_format(attrs['format'])
if for_editor:
try:
return image_format.image_to_editor_html(image, attrs['alt'])
except:
return ''
else:
return image_format.image_to_html(image, attrs['alt'])