From 194720827e4a634d5ee45001e9a091e3162a7698 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 27 Dec 2016 12:12:33 +0100 Subject: [PATCH] error reporting --- apps/catalogue/views.py | 16 ++++++++++++---- lib/librarian | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index e3d98d8c..c43a46f5 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -175,9 +175,13 @@ def book_html(request, pk, rev_pk=None, preview=False): was_published = revision == published_revision or doc.publish_log.filter(revision=revision).exists() - sst = SST.from_string(revision.materialize()) - html = HtmlFormat(sst).build( - files_path='http://%s/media/dynamic/uploads/%s/' % (request.get_host(), pk)).get_string() + try: + sst = SST.from_string(revision.materialize()) + except ValueError as e: + html = e + else: + html = HtmlFormat(sst).build( + files_path='http://%s/media/dynamic/uploads/%s/' % (request.get_host(), pk)).get_string() # response = http.HttpResponse(html, content_type='text/html', mimetype='text/html') # return response @@ -218,7 +222,11 @@ def book_pdf(request, pk, rev_pk): ) if doc.owner_organization is not None and doc.owner_organization.logo: ctx.cover_logo = 'http://%s%s' % (request.get_host(), doc.owner_organization.logo.url) - pdf_file = PdfFormat(sst).build(ctx) + try: + pdf_file = PdfFormat(sst).build(ctx) + except BuildError as e: + from django.http import HttpResponse + return HttpResponse(content=force_str(e.message), content_type='text/plain', status='400') from catalogue.ebook_utils import serve_file return serve_file(pdf_file.get_filename(), '%d.pdf' % doc.pk, 'application/pdf') diff --git a/lib/librarian b/lib/librarian index 5135e076..1428a9d8 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 5135e076096ce04b1dbbb2f6210512d1a44fa237 +Subproject commit 1428a9d8f91b754fe7f9fb96cbdd0d6a2536ffc1 -- 2.20.1