From 1b7a3f045bf7a23ef993d136b481f22258c4a778 Mon Sep 17 00:00:00 2001 From: Ann Paul Date: Fri, 2 Oct 2015 23:17:49 -0700 Subject: [PATCH] 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 --- wagtail/wagtailimages/rich_text.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wagtail/wagtailimages/rich_text.py b/wagtail/wagtailimages/rich_text.py index 38db0f27d3..a80a2c7e1b 100644 --- a/wagtail/wagtailimages/rich_text.py +++ b/wagtail/wagtailimages/rich_text.py @@ -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 "" + + 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'])