Merge pull request #183 from simple-login/api-error
API Error handling for 404 and 500
This commit is contained in:
commit
50cdbc2b74
|
@ -5,6 +5,7 @@ from flask import Blueprint, request, jsonify, g
|
|||
from flask_login import current_user
|
||||
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import ApiKey
|
||||
|
||||
api_bp = Blueprint(name="api", import_name=__name__, url_prefix="/api")
|
||||
|
@ -32,3 +33,19 @@ def require_api_auth(f):
|
|||
return f(*args, **kwargs)
|
||||
|
||||
return decorated
|
||||
|
||||
|
||||
@api_bp.app_errorhandler(404)
|
||||
def not_found(e):
|
||||
return jsonify(error="No such endpoint"), 404
|
||||
|
||||
|
||||
@api_bp.app_errorhandler(Exception)
|
||||
def internal_error(e):
|
||||
LOG.exception(e)
|
||||
return jsonify(error="Internal error"), 500
|
||||
|
||||
|
||||
@api_bp.app_errorhandler(405)
|
||||
def wrong_method(e):
|
||||
return jsonify(error="Method not allowed"), 405
|
||||
|
|
|
@ -87,13 +87,13 @@ def create_app() -> Flask:
|
|||
app.config["SESSION_COOKIE_SECURE"] = True
|
||||
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
|
||||
|
||||
setup_error_page(app)
|
||||
|
||||
init_extensions(app)
|
||||
register_blueprints(app)
|
||||
set_index_page(app)
|
||||
jinja2_filter(app)
|
||||
|
||||
setup_error_page(app)
|
||||
|
||||
setup_favicon_route(app)
|
||||
setup_openid_metadata(app)
|
||||
|
||||
|
@ -136,6 +136,7 @@ def fake_data():
|
|||
activated=True,
|
||||
is_admin=True,
|
||||
otp_secret="base32secret3232",
|
||||
can_use_fido=True,
|
||||
)
|
||||
db.session.commit()
|
||||
user.trial_end = None
|
||||
|
|
Loading…
Reference in a new issue