changeset 29:1dadc59c4b9a

Make the conversion more error prone
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 16 Oct 2014 10:03:32 +0200
parents 1dd40e13da74
children 9d65de2ebe22
files odfcast/convert.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/odfcast/convert.py	Tue Sep 30 16:38:08 2014 +0200
+++ b/odfcast/convert.py	Thu Oct 16 10:03:32 2014 +0200
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 
+import logging
 import tempfile
 
 from flask import request, Response, json, render_template
@@ -9,6 +10,7 @@
 
 from PyPDF2 import PdfFileMerger
 
+log = logging.getLogger(__name__)
 
 ALLOWED_FORMATS = ["pdf", "doc", "docx", "odt"]
 
@@ -40,14 +42,22 @@
 
     def post(self):
         ffile = request.files['file']
+        if not ffile.filename:
+            return "Please upload a file for conversion", 401
+
         fformat = request.form['format']
-
         if not self.is_format_supported(fformat):
             return "Format %s not allowed" % fformat, 401
 
+        mimetype = self.get_mimetype_for_format(fformat)
+
         infile = self.save_form_file(ffile)
-        outfile = self.convert(infile, fformat)
-        mimetype = self.get_mimetype_for_format(fformat)
+        try:
+            outfile = self.convert(infile, fformat)
+        except:
+            log.exception("Conversion error")
+            return "Conversion error", 500
+
         return Response(outfile, mimetype=mimetype)
 
     def get(self):
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)