Optimize api with semantic HTTP status codes (#681)

This commit is contained in:
Dylan
2025-06-23 22:18:17 +08:00
committed by GitHub
parent f9bfe8f510
commit 6d5e741d94
20 changed files with 91 additions and 62 deletions
@@ -58,7 +58,7 @@ class DictDataService:
async with async_db_session.begin() as db:
dict_data = await dict_data_dao.get_by_label(db, obj.label)
if dict_data:
raise errors.ForbiddenError(msg='字典数据已存在')
raise errors.ConflictError(msg='字典数据已存在')
dict_type = await dict_type_dao.get(db, obj.type_id)
if not dict_type:
raise errors.NotFoundError(msg='字典类型不存在')
@@ -79,7 +79,7 @@ class DictDataService:
raise errors.NotFoundError(msg='字典数据不存在')
if dict_data.label != obj.label:
if await dict_data_dao.get_by_label(db, obj.label):
raise errors.ForbiddenError(msg='字典数据已存在')
raise errors.ConflictError(msg='字典数据已存在')
dict_type = await dict_type_dao.get(db, obj.type_id)
if not dict_type:
raise errors.NotFoundError(msg='字典类型不存在')
@@ -49,7 +49,7 @@ class DictTypeService:
async with async_db_session.begin() as db:
dict_type = await dict_type_dao.get_by_code(db, obj.code)
if dict_type:
raise errors.ForbiddenError(msg='字典类型已存在')
raise errors.ConflictError(msg='字典类型已存在')
await dict_type_dao.create(db, obj)
@staticmethod
@@ -67,7 +67,7 @@ class DictTypeService:
raise errors.NotFoundError(msg='字典类型不存在')
if dict_type.code != obj.code:
if await dict_type_dao.get_by_code(db, obj.code):
raise errors.ForbiddenError(msg='字典类型已存在')
raise errors.ConflictError(msg='字典类型已存在')
count = await dict_type_dao.update(db, pk, obj)
return count