diff --git a/app.py b/app.py index dc1e1fe..3f68e58 100644 --- a/app.py +++ b/app.py @@ -19,9 +19,24 @@ app = Flask(__name__) app.config["SECRET_KEY"] = config.FLASK_CONFIG["secret_key"] app.config["SEND_FILE_MAX_AGE_DEFAULT"] = config.FLASK_CONFIG.get("static_cache_timeout", 60) -# Bez Eventlet – tryb wątkowy socketio = SocketIO(app, cors_allowed_origins="*", async_mode="threading", logger=False) +@app.errorhandler(500) +def server_error(error): + app.logger.error(f'Server error: {str(error)}') + return render_template('error.html', + status=500, + title='Błąd serwera', + message='Spróbuj ponownie za chwilę.', + footer=config.FOOTER), 500 +@app.errorhandler(400) +@app.errorhandler(404) +def client_error(error): + return render_template('error.html', + status=error.code, + title=f'Błąd {error.code}', + message='Nieprawidłowe żądanie.', + footer=config.FOOTER), error.code # -------------------- # Helpers @@ -155,9 +170,16 @@ def favicon(): @app.route("/") def index(): + safe_phases = { + k: { + 'label': v['label'], + 'color': v['color'] + } + for k, v in config.PHASES.items() + } return render_template( "index.html", - phases=config.PHASES, + phases=safe_phases, time_ranges=config.TIME_RANGES, default_range=config.DEFAULT_TIME_RANGE, footer=config.FOOTER, diff --git a/templates/base.html b/templates/base.html index 2960368..b7efc0f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -37,9 +37,13 @@ diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..60a374f --- /dev/null +++ b/templates/error.html @@ -0,0 +1,38 @@ + +{% extends "base.html" %} + +{% block content %} +
{{ message }}
+ + + Powrót do monitora + + + {% if config.get('DEBUG', False) %} +
+{{ request.url }}
+{{ error_description if error_description else 'Brak szczegółów' }}
+{{ request.args }}
+
+