fix: create_apikey.dspy 添加重复key返回500,加try/except
添加重复的应用ID或名称时,sor.C()抛Duplicate异常未捕获, 导致500错误而非友好的提示信息。 修复: - 包裹主逻辑在try/except中 - Duplicate/1062错误: 返回'应用ID或名称已存在' - 其他错误: 返回具体错误信息
This commit is contained in:
parent
5b69dd62b5
commit
af142173bb
BIN
scripts/__pycache__/load_path.cpython-310.pyc
Normal file
BIN
scripts/__pycache__/load_path.cpython-310.pyc
Normal file
Binary file not shown.
@ -20,7 +20,8 @@ kw = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async with db.sqlorContext(dbname) as sor:
|
try:
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
orgid = await get_userorgid()
|
orgid = await get_userorgid()
|
||||||
userid = await get_user()
|
userid = await get_user()
|
||||||
ns = {
|
ns = {
|
||||||
@ -42,4 +43,11 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
}
|
}
|
||||||
await sor.C('downapikey', ns1)
|
await sor.C('downapikey', ns1)
|
||||||
return UiMessage(title="create apikey", message=f"apikey created", **kw)
|
return UiMessage(title="create apikey", message=f"apikey created", **kw)
|
||||||
|
except Exception as e:
|
||||||
|
err_msg = str(e)
|
||||||
|
debug(f'create_apikey error: {format_exc()}')
|
||||||
|
if 'Duplicate' in err_msg or '1062' in err_msg:
|
||||||
|
return UiError(title='创建失败', message='应用ID或名称已存在,请使用不同的ID或名称')
|
||||||
|
return UiError(title='创建失败', message=f'创建API Key失败: {err_msg}')
|
||||||
|
|
||||||
return UiError(title='create apikey', message='add apikey error')
|
return UiError(title='create apikey', message='add apikey error')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user