refactor: better error handler (#24422)

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN-
2025-08-25 09:28:42 +08:00
committed by GitHub
parent 9a18911eba
commit fe06d266e9
4 changed files with 113 additions and 78 deletions

View File

@@ -29,7 +29,6 @@ def init_app(app: DifyApp):
methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
expose_headers=["X-Version", "X-Env"],
)
app.register_blueprint(web_bp)
CORS(
@@ -40,10 +39,13 @@ def init_app(app: DifyApp):
methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
expose_headers=["X-Version", "X-Env"],
)
app.register_blueprint(console_app_bp)
CORS(files_bp, allow_headers=["Content-Type"], methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"])
CORS(
files_bp,
allow_headers=["Content-Type"],
methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
)
app.register_blueprint(files_bp)
app.register_blueprint(inner_api_bp)

View File

@@ -20,6 +20,10 @@ login_manager = flask_login.LoginManager()
@login_manager.request_loader
def load_user_from_request(request_from_flask_login):
"""Load user based on the request."""
# Skip authentication for documentation endpoints
if request.path.endswith("/docs") or request.path.endswith("/swagger.json"):
return None
auth_header = request.headers.get("Authorization", "")
auth_token: str | None = None
if auth_header: