diff --git a/src/components/settings/AssistantSettings.vue b/src/components/settings/AssistantSettings.vue index 30269ee..6224039 100644 --- a/src/components/settings/AssistantSettings.vue +++ b/src/components/settings/AssistantSettings.vue @@ -124,7 +124,7 @@ 工具
- +
{{ c.name }} @@ -243,6 +243,7 @@ import { EntityTool, } from "@/api"; import { useIsMobile } from "@/utils/composables"; +import { AxiosError } from "axios"; const dialog = useDialog(); const chatStore = useChatStore(); @@ -317,14 +318,28 @@ const getTools = async () => { }; const createAssistant = async () => { - await getApi().Assistant.apiV1AssistantsPost({ - name: currentAssistant.value.name ?? "", - prompt: currentAssistant.value.prompt ?? "", - description: - currentAssistant.value.description ?? currentAssistant.value.name ?? "", - }); + await getApi() + .Assistant.apiV1AssistantsPost({ + name: currentAssistant.value.name ?? "", + prompt: currentAssistant.value.prompt ?? "", + description: + currentAssistant.value.description ?? currentAssistant.value.name ?? "", + }) + .then(() => { + showCreateDialog.value = false; + }) + .catch((e: AxiosError) => { + if (e.response?.status === 400) { + dialog.error({ + title: "参数错误", + // @ts-ignore 忽略 + content: e.response?.data?.error, + positiveText: "好", + }); + return; + } + }); await getAssistants(); - showCreateDialog.value = false; }; const getLibraries = async () => { diff --git a/src/pages/errors/400.vue b/src/pages/errors/400.vue new file mode 100644 index 0000000..bff4d5c --- /dev/null +++ b/src/pages/errors/400.vue @@ -0,0 +1,12 @@ + + + diff --git a/src/plugins/httpInterceptors.ts b/src/plugins/httpInterceptors.ts index 709480d..7959fea 100644 --- a/src/plugins/httpInterceptors.ts +++ b/src/plugins/httpInterceptors.ts @@ -3,6 +3,7 @@ import { createDiscreteApi, darkTheme, lightTheme, useOsTheme } from "naive-ui"; import type { ConfigProviderProps } from "naive-ui"; import error401 from "@/pages/errors/401.vue"; import error404 from "@/pages/errors/404.vue"; +import error400 from "@/pages/errors/400.vue"; import error500 from "@/pages/errors/500.vue"; const osThemeRef = useOsTheme(); @@ -66,7 +67,16 @@ const response = { data = error.response.data.error.message; } - if (error.response.status === 401) { + if (error.response.status === 400) { + // dialog.error({ + // title: "输入有误", + // content: () => { + // return h(error400, { + // show_footer: false, + // }); + // }, + // }); + } else if (error.response.status === 401) { dialog.error({ title: "401 未授权", content: () => { diff --git a/src/typed-router.d.ts b/src/typed-router.d.ts index 2dfb4e1..c81120a 100644 --- a/src/typed-router.d.ts +++ b/src/typed-router.d.ts @@ -24,6 +24,7 @@ declare module 'vue-router/auto-routes' { '/auth/login': RouteRecordInfo<'/auth/login', '/auth/login', Record, Record>, '/auth/logout': RouteRecordInfo<'/auth/logout', '/auth/logout', Record, Record>, '/chat/[id]/': RouteRecordInfo<'/chat/[id]/', '/chat/:id', { id: ParamValue }, { id: ParamValue }>, + '/errors/400': RouteRecordInfo<'/errors/400', '/errors/400', Record, Record>, '/errors/401': RouteRecordInfo<'/errors/401', '/errors/401', Record, Record>, '/errors/404': RouteRecordInfo<'/errors/404', '/errors/404', Record, Record>, '/errors/500': RouteRecordInfo<'/errors/500', '/errors/500', Record, Record>,