Phase 1 of app.py refactoring - reducing from ~14,455 to ~13,699 lines.
New structure:
- blueprints/reports/ - 4 routes (/raporty/*)
- blueprints/community/contacts/ - 6 routes (/kontakty/*)
- blueprints/community/classifieds/ - 4 routes (/tablica/*)
- blueprints/community/calendar/ - 3 routes (/kalendarz/*)
- utils/ - decorators, helpers, notifications, analytics
- extensions.py - Flask extensions (csrf, login_manager, limiter)
- config.py - environment configurations
Updated templates with blueprint-prefixed url_for() calls.
⚠️ DO NOT DEPLOY before presentation on 2026-01-30 19:00
Tested on DEV: all endpoints working correctly.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
|
Error Handlers
|
|
==============
|
|
|
|
Custom error handlers for the Flask application.
|
|
"""
|
|
|
|
from flask import render_template, jsonify, request
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def register_error_handlers(app):
|
|
"""Register all error handlers with the app."""
|
|
|
|
@app.errorhandler(400)
|
|
def bad_request(e):
|
|
if request.is_json:
|
|
return jsonify({'error': 'Bad request', 'message': str(e)}), 400
|
|
return render_template('errors/400.html'), 400
|
|
|
|
@app.errorhandler(403)
|
|
def forbidden(e):
|
|
if request.is_json:
|
|
return jsonify({'error': 'Forbidden', 'message': 'Access denied'}), 403
|
|
return render_template('errors/403.html'), 403
|
|
|
|
@app.errorhandler(404)
|
|
def not_found(e):
|
|
if request.is_json:
|
|
return jsonify({'error': 'Not found'}), 404
|
|
return render_template('errors/404.html'), 404
|
|
|
|
@app.errorhandler(429)
|
|
def ratelimit_handler(e):
|
|
logger.warning(f"Rate limit exceeded: {request.remote_addr} - {request.path}")
|
|
if request.is_json:
|
|
return jsonify({
|
|
'error': 'Rate limit exceeded',
|
|
'message': 'Zbyt wiele zapytań. Spróbuj ponownie później.'
|
|
}), 429
|
|
return render_template('errors/429.html'), 429
|
|
|
|
@app.errorhandler(500)
|
|
def internal_error(e):
|
|
logger.error(f"Internal server error: {e}")
|
|
if request.is_json:
|
|
return jsonify({'error': 'Internal server error'}), 500
|
|
return render_template('errors/500.html'), 500
|