fix: 优化资源重复的错误提示
Some checks failed
continuous-integration/drone/push Build is failing

1. 后端 course_service.py:
   - 课程名重复时返回 existing_id 和 existing_name
   - 成长路径名重复时返回详细信息

2. 前端 edit-course.vue:
   - 处理409冲突错误,提供跳转到已存在课程的选项

3. 前端 errorHandler.ts:
   - 添加409错误的处理逻辑
   - 添加冲突错误工具函数

4. 前端 position-management.vue, user-management.vue:
   - 改进错误消息提取,显示更详细的错误信息
This commit is contained in:
yuliang_guo
2026-01-29 17:04:15 +08:00
parent 7998b32080
commit 696b48e97a
5 changed files with 117 additions and 11 deletions

View File

@@ -195,8 +195,12 @@ class CourseService(BaseService[Course]):
and_(Course.name == course_in.name, Course.is_deleted == False)
)
)
if existing.scalar_one_or_none():
raise ConflictError(f"课程名称 '{course_in.name}' 已存在")
existing_course = existing.scalar_one_or_none()
if existing_course:
raise ConflictError(
f"课程名称 '{course_in.name}' 已存在",
detail={"existing_id": existing_course.id, "existing_name": existing_course.name}
)
# 创建课程
course_data = course_in.model_dump()
@@ -260,8 +264,12 @@ class CourseService(BaseService[Course]):
)
)
)
if existing.scalar_one_or_none():
raise ConflictError(f"课程名称 '{course_in.name}' 已存在")
existing_course = existing.scalar_one_or_none()
if existing_course:
raise ConflictError(
f"课程名称 '{course_in.name}' 已存在",
detail={"existing_id": existing_course.id, "existing_name": existing_course.name}
)
# 记录状态变更
old_status = course.status
@@ -800,8 +808,12 @@ class GrowthPathService(BaseService[GrowthPath]):
and_(GrowthPath.name == path_in.name, GrowthPath.is_deleted == False)
)
)
if existing.scalar_one_or_none():
raise ConflictError(f"成长路径名称 '{path_in.name}' 已存在")
existing_path = existing.scalar_one_or_none()
if existing_path:
raise ConflictError(
f"成长路径名称 '{path_in.name}' 已存在",
detail={"existing_id": existing_path.id, "existing_name": existing_path.name, "type": "growth_path"}
)
# 验证课程是否存在
if path_in.courses: