From 7d08cde8b8871aa97d7a74bf4e09c68e7f514c5c Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Fri, 29 May 2020 06:59:40 +0200 Subject: [PATCH] Update error handling cover upload --- cps/helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 5a284910..ecb7180d 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -31,8 +31,6 @@ from datetime import datetime, timedelta from tempfile import gettempdir import requests -from babel import Locale as LC -from babel.core import UnknownLocaleError from babel.dates import format_datetime from babel.units import format_unit from flask import send_from_directory, make_response, redirect, abort @@ -56,6 +54,7 @@ except ImportError: try: from PIL import Image as PILImage + from PIL import UnidentifiedImageError use_PIL = True except ImportError: use_PIL = False @@ -535,12 +534,16 @@ def save_cover_from_url(url, book_path): try: img = requests.get(url, timeout=(10, 200)) # ToDo: Error Handling img.raise_for_status() + return save_cover(img, book_path) except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as ex: log.info(u'Cover Download Error %s', ex) return False, _("Error Downloading Cover") - return save_cover(img, book_path) + except UnidentifiedImageError as ex: + log.info(u'File Format Error %s', ex) + return False, _("Cover Format Error") + def save_cover_from_filestorage(filepath, saved_filename, img):