diff options
author | Mark Beierl <mark.beierl@dell.com> | 2017-08-15 17:31:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-15 17:31:39 +0000 |
commit | 1d3a2a843e03b8e36d6ac2069fdb1e143b08c91c (patch) | |
tree | aced76f91b792ac3c58e00d244b93d23c1abcb57 /docker/storperf-reporting | |
parent | eb04143319767bb713844c3121338cab5ca5c994 (diff) | |
parent | dbb0a468ce846ddeed6af9ca4a41cb0c762786b4 (diff) |
Merge "Validation if no json object is found at the given URL JIRA: STORPERF-194"
Diffstat (limited to 'docker/storperf-reporting')
-rw-r--r-- | docker/storperf-reporting/src/app.py | 19 | ||||
-rw-r--r-- | docker/storperf-reporting/src/templates/index.html | 7 |
2 files changed, 22 insertions, 4 deletions
diff --git a/docker/storperf-reporting/src/app.py b/docker/storperf-reporting/src/app.py index c77f60f..62d4d33 100644 --- a/docker/storperf-reporting/src/app.py +++ b/docker/storperf-reporting/src/app.py @@ -8,7 +8,7 @@ ############################################################################## from flask import Flask, redirect, url_for, request, render_template, session -from flask import send_from_directory +from flask import send_from_directory, flash import urllib import json app = Flask(__name__) @@ -17,9 +17,13 @@ app.secret_key = 'storperf_graphing_module' @app.route('/reporting/success/') def success(): - data = urllib.urlopen(session["url"]).read() - data = json.loads(data) - return render_template('plot_tables.html', data=data) + try: + data = urllib.urlopen(session["url"]).read() + data = json.loads(data) + return render_template('plot_tables.html', data=data) + except Exception as e: + session['server_error'] = e.message + ' ' + repr(e.args) + return redirect(url_for('file_not_found')) @app.route('/reporting/url', methods=['POST', 'GET']) @@ -30,6 +34,13 @@ def url(): return redirect(url_for('success')) +@app.route('/reporting/file_not_found/') +def file_not_found(): + error = session.get('server_error') + flash("Server Error: " + error) + return redirect(url_for('index')) + + @app.route('/reporting/js/<path:path>') def js(path): return send_from_directory('static/js/', path) diff --git a/docker/storperf-reporting/src/templates/index.html b/docker/storperf-reporting/src/templates/index.html index 35cea1a..ab4e539 100644 --- a/docker/storperf-reporting/src/templates/index.html +++ b/docker/storperf-reporting/src/templates/index.html @@ -26,6 +26,13 @@ </div> </form> </div> + {% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} + <div class="alert alert-danger alert-dismissible" role="alert"> + <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span> + </button> + {{ message }} + </div> + {% endfor %} {% endif %} {% endwith %} </div> </div> </body> |