aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorPjotr Prins2016-10-02 11:06:02 +0000
committerPjotr Prins2016-10-02 11:06:02 +0000
commit3496c5eeae6d9d6064188720902b0cc1b415f610 (patch)
tree20892c7b2c23a45cb7e68d8196e30d3e0ef02733 /wqflask
parent9b3c087e46b6dfdc2fe686a60ac26e98c7cbe93d (diff)
downloadgenenetwork2-3496c5eeae6d9d6064188720902b0cc1b415f610.tar.gz
Error page: use cookies to fixate the animation for one error
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/templates/error.html3
-rw-r--r--wqflask/wqflask/views.py28
2 files changed, 16 insertions, 15 deletions
diff --git a/wqflask/wqflask/templates/error.html b/wqflask/wqflask/templates/error.html
index a2eaad5c..9d9e66d4 100644
--- a/wqflask/wqflask/templates/error.html
+++ b/wqflask/wqflask/templates/error.html
@@ -17,8 +17,7 @@
together.
</p>
<p>
- <b>It is important to report this so we
- can fix it</b>.
+ <b>It is important to report this error so we can fix it for everyone</b>.
</p>
<p>
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 85c2c824..40a77df3 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -29,7 +29,7 @@ import base64
import array
import sqlalchemy
from wqflask import app
-from flask import g, Response, request, render_template, send_from_directory, jsonify, redirect
+from flask import g, Response, request, make_response, render_template, send_from_directory, jsonify, redirect
from wqflask import search_results
from wqflask import gsearch
from wqflask import update_search_results
@@ -89,23 +89,25 @@ def shutdown_session(exception=None):
@app.errorhandler(Exception)
def handle_bad_request(e):
- logger.error(str(e))
+ err_msg = str(e)
+ logger.error(err_msg)
+ # get the stack trace and send it to the logger
exc_type, exc_value, exc_traceback = sys.exc_info()
- # print "*** format_exc, first and last line:"
- # logger.error(formatted_lines[0])
- # logger.error(formatted_lines[-3])
- # logger.error(formatted_lines[-2])
- # logger.error(formatted_lines[-1])
logger.error(traceback.format_exc())
formatted_lines = traceback.format_exc().splitlines()
- # for file in os.listdir("./wqflask/static/gif/error"):
- # if file.endswith(".gif"):
- # print(file)
+ # Handle random animations
+ # Use a cookie to have one animation on refresh
+ animation = request.cookies.get(err_msg)
+ if not animation:
+ list = [fn for fn in os.listdir("./wqflask/static/gif/error") if fn.endswith(".gif") ]
+ animation = random.choice(list)
- list = [fn for fn in os.listdir("./wqflask/static/gif/error") if fn.endswith(".gif") ]
- # print(list)
- return render_template("error.html",message=str(e),stack=formatted_lines,error_image=random.choice(list))
+ resp = make_response(render_template("error.html",message=err_msg,stack=formatted_lines,error_image=animation))
+
+ # logger.error("Set cookie %s with %s" % (err_msg, animation))
+ resp.set_cookie(err_msg,animation)
+ return resp
@app.route("/")
def index_page():