Repository: chaoss/augur

Issue:
Create a pretty 500 error response on front end
In the unlikely event of a 500 error, add a page that is something visually appealing. 


Discussion:
Hey, @sgoggins, I would like to work on it. Can you assign this issue to me?
Also where do I have to add this page


Resolving patch:
diff --git a/augur/api/view/augur_view.py b/augur/api/view/augur_view.py
--- a/augur/api/view/augur_view.py
+++ b/augur/api/view/augur_view.py
@@ -1,8 +1,9 @@
 from flask import Flask, render_template, redirect, url_for, session, request, jsonify
 from flask_login import LoginManager
+from io import StringIO
 from .utils import *
-from .url_converters import *
 from .init import logger
+from .url_converters import *
 
 # from .server import User
 from ..server import app, db_session
@@ -10,7 +11,7 @@
 from augur.api.routes import AUGUR_API_VERSION
 from augur.api.util import get_bearer_token
 
-import time
+import time, traceback
 
 login_manager = LoginManager()
 
@@ -37,6 +38,22 @@ def unsupported_method(error):
     
     return render_message("405 - Method not supported", "The resource you are trying to access does not support the request method used"), 405
 
+@app.errorhandler(500)
+def internal_server_error(error):
+    if AUGUR_API_VERSION in str(request.path):
+        return jsonify({"status": error.original_exception}), 500
+    error = error.original_exception
+    try:
+        errout = StringIO()
+        traceback.print_tb(error.__traceback__, file=errout)
+        # traceback.print_exception(error, file=errout)
+        stacktrace = errout.getvalue()
+        errout.close()
+    except Exception as e:
+        logger.error(e)
+    
+    return render_message("500 - Internal Server Error", "An error occurred while trying to service your request. Please try again, and if the issue persists, please file a GitHub issue with the below error message:", error=stacktrace), 500
+
 @login_manager.unauthorized_handler
 def unauthorized():
     if AUGUR_API_VERSION in str(request.path):
@@ -80,8 +97,6 @@ def load_user(user_id):
 
 @login_manager.request_loader
 def load_user_request(request):
-
-    print(f"Current time of user request: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
     token = get_bearer_token()
 
     current_time = int(time.time())
diff --git a/augur/api/view/routes.py b/augur/api/view/routes.py
--- a/augur/api/view/routes.py
+++ b/augur/api/view/routes.py
@@ -302,6 +302,10 @@ def user_group_view():
     # return renderRepos("table", None, data, sort, rev, params.get("page"), True)
     return render_module("user-group-repos-table", title="Repos", repos=data, query_key=None, activePage=params["page"], pages=page_count, offset=pagination_offset, PS="user_group_view", reverse = rev, sorting = params.get("sort"), group=group)
 
+@app.route('/error')
+def throw_exception():
+    raise Exception("This Exception intentionally raised")
+
 """ ----------------------------------------------------------------
 Admin dashboard:
     View the admin dashboard.
diff --git a/augur/api/view/utils.py b/augur/api/view/utils.py
--- a/augur/api/view/utils.py
+++ b/augur/api/view/utils.py
@@ -434,8 +434,8 @@ def renderRepos(view, query, data, sorting = None, rev = False, page = None, fil
     Renders a simple page with the given message information, and optional page
     title and redirect
 """
-def render_message(messageTitle, messageBody = None, title = None, redirect = None, pause = None):
-    return render_module("notice", messageTitle=messageTitle, messageBody=messageBody, title=title, redirect=redirect, pause=pause)
+def render_message(messageTitle, messageBody = None, title = None, redirect = None, pause = None, **kwargs):
+    return render_module("notice", messageTitle=messageTitle, messageBody=messageBody, title=title, redirect=redirect, pause=pause, **kwargs)
 
 """ ----------------------------------------------------------------
 """


Test patch: