From cc4b69e631b3bbc23968841adbe3309265ae05ca Mon Sep 17 00:00:00 2001 From: root Date: Wed, 10 Dec 2025 16:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=A5=E5=BF=97API=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了诊断500错误,在日志API中添加: 1. 完整的try-except错误捕获 2. 详细的调试日志输出: - 请求用户和任务ID - 权限检查结果 - 查询过程和结果 - 具体的错误信息和堆栈跟踪 3. 返回详细错误信息给前端(开发模式) 现在可以通过应用日志查看具体的500错误原因。 位置: app.py 第3274-3301行 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 3446c4e..a71bdd4 100755 --- a/app.py +++ b/app.py @@ -3275,15 +3275,30 @@ def run_schedule_now_api(schedule_id): @login_required def get_schedule_logs_api(schedule_id): """获取定时任务执行日志""" - schedule = database.get_schedule_by_id(schedule_id) - if not schedule: - return jsonify({"error": "定时任务不存在"}), 404 - if schedule['user_id'] != current_user.id: - return jsonify({"error": "无权访问"}), 403 + try: + print(f"[API日志] 用户 {current_user.id} 请求查看定时任务#{schedule_id}的执行日志") - limit = request.args.get('limit', 10, type=int) - logs = database.get_schedule_execution_logs(schedule_id, limit) - return jsonify(logs) + schedule = database.get_schedule_by_id(schedule_id) + if not schedule: + print(f"[API日志] 定时任务#{schedule_id}不存在") + return jsonify({"error": "定时任务不存在"}), 404 + + if schedule['user_id'] != current_user.id: + print(f"[API日志] 用户 {current_user.id} 无权访问定时任务#{schedule_id}(属于用户{schedule['user_id']})") + return jsonify({"error": "无权访问"}), 403 + + limit = request.args.get('limit', 10, type=int) + print(f"[API日志] 开始查询定时任务#{schedule_id}的执行日志,限制{limit}条") + + logs = database.get_schedule_execution_logs(schedule_id, limit) + print(f"[API日志] 查询到{len(logs)}条日志") + + return jsonify(logs) + except Exception as e: + print(f"[API日志] 查询定时任务#{schedule_id}日志时出错: {str(e)}") + import traceback + traceback.print_exc() + return jsonify({"error": f"服务器错误: {str(e)}"}), 500 # ==================== 批量操作API ====================