wywalenie error handlerow db
This commit is contained in:
41
app.py
41
app.py
@@ -43,14 +43,12 @@ from flask_socketio import SocketIO, emit, join_room
|
||||
from config import Config
|
||||
from PIL import Image, ExifTags, ImageFilter, ImageOps
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from werkzeug.exceptions import InternalServerError
|
||||
from sqlalchemy import func, extract, inspect, or_, case, text
|
||||
from sqlalchemy.orm import joinedload
|
||||
from collections import defaultdict, deque
|
||||
from functools import wraps
|
||||
from flask_talisman import Talisman
|
||||
from flask_session import Session
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
|
||||
# OCR
|
||||
@@ -261,45 +259,6 @@ class Receipt(db.Model):
|
||||
shopping_list = db.relationship("ShoppingList", back_populates="receipts")
|
||||
|
||||
|
||||
def render_db_unavailable():
|
||||
app.logger.error("[Błąd DB] Baza danych niedostępna")
|
||||
if request.accept_mimetypes.best == "application/json":
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"error": "Baza danych jest obecnie niedostępna. Spróbuj ponownie później."
|
||||
}
|
||||
),
|
||||
503,
|
||||
)
|
||||
|
||||
return (
|
||||
render_template(
|
||||
"errors.html",
|
||||
code=503,
|
||||
title="Błąd połączenia z bazą danych",
|
||||
message="Nie udało się połączyć z bazą danych. Spróbuj ponownie później.",
|
||||
),
|
||||
503,
|
||||
)
|
||||
|
||||
|
||||
@app.errorhandler(OperationalError)
|
||||
def handle_db_error(e):
|
||||
app.logger.error(f"[Błąd DB] {e}")
|
||||
return render_db_unavailable()
|
||||
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_any_exception(e):
|
||||
orig_exc = getattr(e, "original_exception", None)
|
||||
if isinstance(e, OperationalError) or isinstance(orig_exc, OperationalError):
|
||||
app.logger.error(f"[Błąd DB] {orig_exc or e}")
|
||||
return render_db_unavailable()
|
||||
|
||||
raise e
|
||||
|
||||
|
||||
def hash_password(password):
|
||||
pepper = app.config["BCRYPT_PEPPER"]
|
||||
peppered = (password + pepper).encode("utf-8")
|
||||
|
Reference in New Issue
Block a user