fix: 工单提交422错误处理 + SQL模板占位符校验

- TicketCreatePage: Pydantic 422 detail 是对象数组,前端错误处理改为检测数组并拼接 msg
- QueriesPage: 执行前检查 SQL 中未替换的 {table}/{db}/{collection} 占位符,阻止执行
- QueriesPage: 同步修复 422 detail 数组的错误处理
This commit is contained in:
logan committed 2026-05-24 15:37:08 +08:00
1 parent 0aa4595c90
commit ca99f0ea7f
2 files changed
+10 -3

No files matched your search

+6 -1
View File
@@ -343,6 +343,10 @@ function NewQueryPanel({
const handleExecute = useCallback(async () => {
if (!sql || !instanceId) { setError('请选择实例并输入查询语句'); return; }
// 检查未替换的模板占位符
if (/\{(?:table|db|collection)\}/.test(sql)) {
setError('SQL 中含有未替换的占位符 {table}/{db}/{collection},请先替换或删除'); return;
}
setExecuting(true);
setError('');
setResult(null);
@@ -368,7 +372,8 @@ function NewQueryPanel({
favorite: false,
});
} catch (e: unknown) {
const msg = (e as { response?: { data?: { detail?: string } } })?.response?.data?.detail || '查询失败';
const raw = (e as { response?: { data?: { detail?: string | Array<{ msg: string }> } } })?.response?.data?.detail;
const msg = Array.isArray(raw) ? raw.map((v) => v.msg).join('; ') : (raw || '查询失败');
setError(msg);
onExecuted({
id: Date.now(),
+4 -2
View File
@@ -398,8 +398,10 @@ export default function TicketCreatePage() {
});
navigate('/tickets');
} catch (e: unknown) {
const err = e as { response?: { data?: { detail?: string } } };
setError(err?.response?.data?.detail || '提交失败,请稍后重试');
const err = e as { response?: { data?: { detail?: string | Array<{ msg: string }> } } };
const raw = err?.response?.data?.detail;
const msg = Array.isArray(raw) ? raw.map((v) => v.msg).join('; ') : (raw || '提交失败,请稍后重试');
setError(msg);
} finally { setSubmitting(false); }
}, [title, sqlContent, instanceId, database, reason, priority, rollbackSql, instances, dbType, navigate]);