From 499b67d3e17531fa080e50c4659151e0515245b9 Mon Sep 17 00:00:00 2001 From: eric Date: Tue, 2 Jun 2015 23:45:30 -0400 Subject: [PATCH 1/2] handle the bad link error --- frontend/templates/kindle_response_message.html | 2 ++ frontend/views.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frontend/templates/kindle_response_message.html b/frontend/templates/kindle_response_message.html index 9b783f0e..20ebc620 100644 --- a/frontend/templates/kindle_response_message.html +++ b/frontend/templates/kindle_response_message.html @@ -6,3 +6,5 @@ {% endifequal %} {% ifequal message 3 %}Please enter a valid Kindle email. {% endifequal %} +{% ifequal message 4 %}Well, this is awkward our ebook link is bad. We'll look into the error. +{% endifequal %} diff --git a/frontend/views.py b/frontend/views.py index 0b358646..58432d6a 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -3269,11 +3269,15 @@ def send_to_kindle(request, work_id, javascript='0'): """ filehandle = urllib.urlopen(ebook_url) if not filesize: - filesize = int(filehandle.info().getheaders("Content-Length")[0]) - if ebook: - ebook.filesize = filesize if filesize < 2147483647 else 2147483647 # largest safe positive integer - ebook.save() - + try: + filesize = int(filehandle.info().getheaders("Content-Length")[0]) + if ebook: + ebook.filesize = filesize if filesize < 2147483647 else 2147483647 # largest safe positive integer + ebook.save() + except IndexError: + # response has no Content-Length header probably a bad link + logger.error('Bad link error: %s', ebook_url) + return local_response(request, javascript, context, 4) if filesize > models.send_to_kindle_limit: logger.info('ebook %s is too large to be emailed' % work.id) return local_response(request, javascript, context, 0) @@ -3284,7 +3288,7 @@ def send_to_kindle(request, work_id, javascript='0'): email.attach(title + '.' + ebook_format, filehandle.read()) email.send() except: - logger.warning('Unexpected error: %s', sys.exc_info()) + logger.error('Unexpected error: %s', sys.exc_info()) return local_response(request, javascript, context, 1) if request.POST.has_key('kindle_email') and not request.user.is_authenticated(): From 6ec36e001db4b148f6f8db52f593c5c5dcac4f23 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Wed, 3 Jun 2015 07:02:49 -0700 Subject: [PATCH 2/2] adding a colon to error message "Well, this is awkward our ebook link is bad" to "Well, this is awkward: our ebook link is bad" --- frontend/templates/kindle_response_message.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/templates/kindle_response_message.html b/frontend/templates/kindle_response_message.html index 20ebc620..2251caa5 100644 --- a/frontend/templates/kindle_response_message.html +++ b/frontend/templates/kindle_response_message.html @@ -6,5 +6,5 @@ {% endifequal %} {% ifequal message 3 %}Please enter a valid Kindle email. {% endifequal %} -{% ifequal message 4 %}Well, this is awkward our ebook link is bad. We'll look into the error. +{% ifequal message 4 %}Well, this is awkward: our ebook link is bad. We'll look into the error. {% endifequal %}