Implement error handling in app.py, update deployment instructions in README_DASHBOARD.md, and modify deploy.sh for rsync-based deployment. Adjust base.html to safely access session variables.
This commit is contained in:
22
app.py
22
app.py
@@ -1,4 +1,6 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, flash
|
||||
import traceback
|
||||
import sys
|
||||
import config
|
||||
from auth_helpers import verify_admin
|
||||
from db import get_cursor
|
||||
@@ -7,6 +9,20 @@ app = Flask(__name__)
|
||||
app.secret_key = config.SECRET_KEY
|
||||
|
||||
|
||||
@app.errorhandler(500)
|
||||
def handle_500(e):
|
||||
tb = traceback.format_exc()
|
||||
print(tb, file=sys.stderr, flush=True)
|
||||
# Show traceback in response for debugging (remove in production if desired)
|
||||
escaped = tb.replace("<", "<").replace(">", ">")
|
||||
return (
|
||||
"<h1>Internal Server Error</h1>"
|
||||
"<p>The error has been logged. Details below (also in journalctl -u portal-auth-dashboard):</p>"
|
||||
"<pre style='white-space:pre-wrap;font-size:small'>" + escaped + "</pre>",
|
||||
500,
|
||||
)
|
||||
|
||||
|
||||
def login_required(f):
|
||||
from functools import wraps
|
||||
@wraps(f)
|
||||
@@ -68,12 +84,12 @@ def table_view(name):
|
||||
with get_cursor() as cur:
|
||||
cur.execute(f'SELECT * FROM "{name}" ORDER BY 1 DESC LIMIT 500')
|
||||
rows = cur.fetchall()
|
||||
# Convert dict rows to list of dicts with string values for display; keep raw row for actions (e.g. session_id, id)
|
||||
# Convert to plain dicts so Jinja and serialization don't hit RealDictRow issues
|
||||
data = []
|
||||
raw_rows = []
|
||||
for r in rows:
|
||||
data.append({k: (str(v) if v is not None else "") for k, v in r.items()})
|
||||
# Keep original rows for action URLs (session_id, id) so we don't rely on truncated display
|
||||
raw_rows = rows
|
||||
raw_rows.append(dict(r))
|
||||
columns = list(rows[0].keys()) if rows else TABLE_COLUMNS.get(name, [])
|
||||
return render_template("table.html", table_name=name, rows=data, raw_rows=raw_rows, columns=columns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user