[System] Detect offline database
This commit is contained in:
parent
1d36aa4033
commit
602e1bc941
|
@ -3,6 +3,7 @@ from flask import Flask, current_app
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from flask.json import JSONEncoder, jsonify
|
from flask.json import JSONEncoder, jsonify
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
from . import logger
|
from . import logger
|
||||||
|
@ -93,6 +94,9 @@ def create_app():
|
||||||
if isinstance(e, HTTPException):
|
if isinstance(e, HTTPException):
|
||||||
logger.debug(e.description, exc_info=True)
|
logger.debug(e.description, exc_info=True)
|
||||||
return jsonify({"error": e.description}), e.code
|
return jsonify({"error": e.description}), e.code
|
||||||
|
if isinstance(e, OperationalError):
|
||||||
|
logger.error(e, exc_info=True)
|
||||||
|
return {"error": "Database unavailable"}, 504
|
||||||
logger.error(str(e), exc_info=True)
|
logger.error(str(e), exc_info=True)
|
||||||
return jsonify({"error": "Internal server error occurred"}), 500
|
return jsonify({"error": "Internal server error occurred"}), 500
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
from werkzeug.exceptions import NotFound, BadRequest
|
from werkzeug.exceptions import NotFound, BadRequest
|
||||||
|
|
||||||
from flaschengeist.utils.hook import Hook
|
from flaschengeist.utils.hook import Hook
|
||||||
|
@ -9,8 +10,9 @@ from flaschengeist import logger
|
||||||
|
|
||||||
def login_user(username, password):
|
def login_user(username, password):
|
||||||
logger.info("login user {{ {} }}".format(username))
|
logger.info("login user {{ {} }}".format(username))
|
||||||
user = User.query.filter(User.userid == username).one_or_none()
|
try:
|
||||||
if user is None:
|
user = User.query.filter(User.userid == username).one()
|
||||||
|
except NoResultFound:
|
||||||
user = User(userid=username)
|
user = User(userid=username)
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
if current_app.config["FG_AUTH_BACKEND"].login(user, password):
|
if current_app.config["FG_AUTH_BACKEND"].login(user, password):
|
||||||
|
|
Loading…
Reference in New Issue