From 8509b0567b35829ceac4d47b66686c15267d5794 Mon Sep 17 00:00:00 2001 From: Kobe Date: Fri, 6 Jun 2025 10:35:56 +0200 Subject: [PATCH] error pages --- __pycache__/models.cpython-313.pyc | Bin 35519 -> 35519 bytes app.py | 37 +++++++++++++++ routes/__pycache__/main.cpython-313.pyc | Bin 77824 -> 77824 bytes routes/__pycache__/rooms.cpython-313.pyc | Bin 21113 -> 21113 bytes templates/common/400.html | 19 ++++++++ templates/common/401.html | 19 ++++++++ templates/common/403.html | 19 ++++++++ templates/common/404.html | 15 +++++++ templates/common/500.html | 55 +++++++++++++++++++++++ 9 files changed, 164 insertions(+) create mode 100644 templates/common/400.html create mode 100644 templates/common/401.html create mode 100644 templates/common/403.html create mode 100644 templates/common/404.html create mode 100644 templates/common/500.html diff --git a/__pycache__/models.cpython-313.pyc b/__pycache__/models.cpython-313.pyc index 73b579e5972d9fa1fae696ef807dafa346673f2b..4d2cb8b11ead17eca43d0055c5ed3012ca36bdc6 100644 GIT binary patch delta 21 bcmdl#m1+M}Ca%xCyj%=G(79wI*VZloP0$AQ delta 21 bcmdl#m1+M}Ca%xCyj%=GaJFwF*VZloPWlHU diff --git a/app.py b/app.py index 516d599..a99297e 100644 --- a/app.py +++ b/app.py @@ -53,6 +53,15 @@ def create_app(): db.session.commit() return dict(config=app.config, site_settings=site_settings) + @app.context_processor + def inject_unread_notifications(): + from flask_login import current_user + from utils import get_unread_count + if current_user.is_authenticated: + unread_count = get_unread_count(current_user.id) + return {'unread_notifications': unread_count} + return {'unread_notifications': 0} + @app.template_filter('asset_version') def asset_version_filter(filename): """Template filter to get version hash for static assets""" @@ -134,6 +143,34 @@ def create_app(): app = create_app() +@app.errorhandler(404) +def page_not_found(e): + from flask import render_template + return render_template('common/404.html'), 404 + +@app.errorhandler(403) +def forbidden(e): + from flask import render_template + return render_template('common/403.html'), 403 + +@app.errorhandler(401) +def unauthorized(e): + from flask import render_template + return render_template('common/401.html'), 401 + +@app.errorhandler(400) +def bad_request(e): + from flask import render_template + return render_template('common/400.html'), 400 + +@app.errorhandler(500) +def internal_server_error(e): + from flask import render_template + import traceback + error_details = f"{str(e)}\n\n{traceback.format_exc()}" + app.logger.error(f"500 error: {error_details}") + return render_template('common/500.html', error=error_details), 500 + @app.route('/uploads/profile_pics/') def profile_pic(filename): return send_from_directory('/app/uploads/profile_pics', filename) diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index 559ffd548262e2a7180692d2fb368a4d10664f25..52cdf19044acc93ee919f34b881a8431e6f57cb3 100644 GIT binary patch delta 24 ecmZp8z|!!5h3hjfFBbz4bS`P++RDZFO& +

400

+

Bad Request

+

Sorry, the request could not be processed. Please check your input and try again.

+
+ + Back to Dashboard + + +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/common/401.html b/templates/common/401.html new file mode 100644 index 0000000..f919593 --- /dev/null +++ b/templates/common/401.html @@ -0,0 +1,19 @@ +{% extends "common/base.html" %} + +{% block title %}Authentication Required - 401{% endblock %} + +{% block content %} +
+

401

+

Authentication Required

+

Please log in to access this resource.

+
+ + Log In + + +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/common/403.html b/templates/common/403.html new file mode 100644 index 0000000..4942531 --- /dev/null +++ b/templates/common/403.html @@ -0,0 +1,19 @@ +{% extends "common/base.html" %} + +{% block title %}Access Denied - 403{% endblock %} + +{% block content %} +
+

403

+

Access Denied

+

Sorry, you don't have permission to access this resource.

+
+ + Back to Dashboard + + +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/common/404.html b/templates/common/404.html new file mode 100644 index 0000000..8138db2 --- /dev/null +++ b/templates/common/404.html @@ -0,0 +1,15 @@ +{% extends "common/base.html" %} + +{% block title %}Page Not Found - 404{% endblock %} + +{% block content %} +
+

404

+

Page Not Found

+

Sorry, the page you are looking for does not exist or has been moved.

+

If you were trying to access a room, conversation, or file, it may have been deleted by an administrator.

+ + Back to Dashboard + +
+{% endblock %} \ No newline at end of file diff --git a/templates/common/500.html b/templates/common/500.html new file mode 100644 index 0000000..2502e53 --- /dev/null +++ b/templates/common/500.html @@ -0,0 +1,55 @@ +{% extends "common/base.html" %} + +{% block title %}Server Error - 500{% endblock %} + +{% block content %} +
+

500

+

Internal Server Error

+

Sorry, something went wrong on our end. Our team has been notified and we're working to fix it.

+
+ + Back to Dashboard + + +
+ + +
+ +
+
+
+
+
Error Details
+ +
+
{{ error }}
+
+
+
+
+
+ +{% block extra_js %} + +{% endblock %} +{% endblock %} \ No newline at end of file