fix: 工单提交422错误处理 + SQL模板占位符校验
- TicketCreatePage: Pydantic 422 detail 是对象数组,前端错误处理改为检测数组并拼接 msg
- QueriesPage: 执行前检查 SQL 中未替换的 {table}/{db}/{collection} 占位符,阻止执行
- QueriesPage: 同步修复 422 detail 数组的错误处理
This commit is contained in:
1 parent
0aa4595c90
commit
ca99f0ea7f
2 files changed
+10
-3
No files matched your search
@@ -343,6 +343,10 @@ function NewQueryPanel({
|
|||||||
|
|
||||||
const handleExecute = useCallback(async () => {
|
const handleExecute = useCallback(async () => {
|
||||||
if (!sql || !instanceId) { setError('请选择实例并输入查询语句'); return; }
|
if (!sql || !instanceId) { setError('请选择实例并输入查询语句'); return; }
|
||||||
|
// 检查未替换的模板占位符
|
||||||
|
if (/\{(?:table|db|collection)\}/.test(sql)) {
|
||||||
|
setError('SQL 中含有未替换的占位符 {table}/{db}/{collection},请先替换或删除'); return;
|
||||||
|
}
|
||||||
setExecuting(true);
|
setExecuting(true);
|
||||||
setError('');
|
setError('');
|
||||||
setResult(null);
|
setResult(null);
|
||||||
@@ -368,7 +372,8 @@ function NewQueryPanel({
|
|||||||
favorite: false,
|
favorite: false,
|
||||||
});
|
});
|
||||||
} catch (e: unknown) {
|
} 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);
|
setError(msg);
|
||||||
onExecuted({
|
onExecuted({
|
||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
|
|||||||
@@ -398,8 +398,10 @@ export default function TicketCreatePage() {
|
|||||||
});
|
});
|
||||||
navigate('/tickets');
|
navigate('/tickets');
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const err = e as { response?: { data?: { detail?: string } } };
|
const err = e as { response?: { data?: { detail?: string | Array<{ msg: string }> } } };
|
||||||
setError(err?.response?.data?.detail || '提交失败,请稍后重试');
|
const raw = err?.response?.data?.detail;
|
||||||
|
const msg = Array.isArray(raw) ? raw.map((v) => v.msg).join('; ') : (raw || '提交失败,请稍后重试');
|
||||||
|
setError(msg);
|
||||||
} finally { setSubmitting(false); }
|
} finally { setSubmitting(false); }
|
||||||
}, [title, sqlContent, instanceId, database, reason, priority, rollbackSql, instances, dbType, navigate]);
|
}, [title, sqlContent, instanceId, database, reason, priority, rollbackSql, instances, dbType, navigate]);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user