webapp: avoid raising an unhandled FileNotFoundError
authorHelmut Grohne <helmut@subdivi.de>
Tue, 12 Mar 2019 05:17:02 +0000 (06:17 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Tue, 12 Mar 2019 05:17:02 +0000 (06:17 +0100)
webapp.py

index 9e69a18..84e83fb 100644 (file)
--- a/webapp.py
+++ b/webapp.py
@@ -156,6 +156,9 @@ def show_log(filename):
     if filename.endswith(".xz"):
         return flask.send_from_directory("logs", filename,
                                          mimetype="application/octet-stream")
-    filename += ".xz"
-    return flask.send_file(lzma.open(flask.safe_join("logs", filename), "rb"),
-                           mimetype="text/plain")
+    filename = flask.safe_join("logs", filename + ".xz")
+    try:
+        return flask.send_file(lzma.open(filename, "rb"),
+                               mimetype="text/plain")
+    except FileNotFoundError:
+        raise werkzeug.exceptions.NotFound()