Input validation work and error handling

This commit is contained in:
Bradley committed 2026-11-13 22:18:45 -05:00
1 parent 4e2520ee76
commit 554b7cc82c
20 files changed
+627 -96

No files matched your search

+11 -1
View File
@@ -1,4 +1,4 @@
from flask import Flask, g
from flask import Flask, g, jsonify, render_template, request
from blueprints.home.home import home_bp
from blueprints.upload_photo.upload_photo import upload_photo_bp
from blueprints.upload_video.upload_video import upload_video_bp
@@ -7,6 +7,7 @@ from blueprints.youtube_download.youtube_download import youtube_download_bp
from blueprints.media_library.media_library import media_library_bp
import os
import json
import sqlite3
with open("config.json", 'r') as config_file:
config_json = json.loads(config_file.read())
@@ -26,6 +27,15 @@ app.register_blueprint(youtube_download_bp)
app.register_blueprint(media_library_bp)
@app.errorhandler(sqlite3.Error)
def database_error(error):
app.logger.exception('Database request failed')
message = 'The database is unavailable. Please try again or contact the administrator.'
if request.path.startswith('/upload/') or request.path == '/media/status':
return jsonify(status='FAILED', error=message), 503
return render_template('database_error.html', message=message), 503
@app.teardown_appcontext
def close_database(error):
db = g.pop('_database', None)