error reporting
authorJan Szejko <janek37@gmail.com>
Tue, 27 Dec 2016 11:12:33 +0000 (12:12 +0100)
committerJan Szejko <janek37@gmail.com>
Tue, 27 Dec 2016 11:13:18 +0000 (12:13 +0100)
apps/catalogue/views.py
lib/librarian

index e3d98d8..c43a46f 100644 (file)
@@ -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')
index 5135e07..1428a9d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5135e076096ce04b1dbbb2f6210512d1a44fa237
+Subproject commit 1428a9d8f91b754fe7f9fb96cbdd0d6a2536ffc1