changeset 61:d8fc52aceb9c

Handle errors during merge of pdf documents
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 12 Nov 2014 12:41:38 +0100
parents ae377f7eed18
children 16352bd395fa
files odfcast/convert.py
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/odfcast/convert.py	Wed Nov 12 12:40:31 2014 +0100
+++ b/odfcast/convert.py	Wed Nov 12 12:41:38 2014 +0100
@@ -9,6 +9,7 @@
 from py3o.template import Template
 
 from PyPDF2 import PdfFileMerger
+from PyPDF2.utils import PyPdfError
 
 from werkzeug.utils import escape
 
@@ -197,14 +198,18 @@
         merger = PdfFileMerger()
         ffiles = request.files.getlist('files')
 
-        for ffile in ffiles:
-            merger.append(ffile)
+        try:
+            for ffile in ffiles:
+                merger.append(ffile)
 
-        outfile = tempfile.NamedTemporaryFile()
+            outfile = tempfile.NamedTemporaryFile()
 
-        merger.write(outfile)
-        merger.close()
-        outfile.seek(0)
+            merger.write(outfile)
+            merger.close()
+            outfile.seek(0)
+        except PyPdfError, e:
+            log.exception("Merge error")
+            return MergeErrorResponse(details=str(e))
 
         log.debug("PDF documents merged")
         return Response(outfile, mimetype=PDF_MIMETYPE)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)