fix(runtime): preserve explicit replies and report bot configuration errors

This commit is contained in:
RockChinQ
2026-09-10 17:21:22 +08:00
parent b7a04f7a24
commit 8903a40c41
41 changed files with 1108 additions and 155 deletions
+4 -7
View File
@@ -24,6 +24,7 @@ import { useTranslation } from 'react-i18next';
import { Settings, FileText, Users, RefreshCw, Trash2 } from 'lucide-react';
import { cn } from '@/lib/utils';
import { toast } from 'sonner';
import { showBotError } from './bot-error';
import { useCurrentWorkspace } from '@/app/infra/http';
import { Bot } from '@/app/infra/entities/api';
import EntityBasicInfoDialog, {
@@ -91,9 +92,9 @@ export default function BotDetailContent({ id }: { id: string }) {
current ? { ...current, enable: checked } : current,
);
refreshBots();
} catch {
} catch (error) {
setBotEnabled(prev);
toast.error(t('bots.setBotEnableError'));
showBotError(error, t('bots.setBotEnableError'), t);
}
},
[id, botEnabled, refreshBots, t],
@@ -129,11 +130,7 @@ export default function BotDetailContent({ id }: { id: string }) {
await refreshBots();
toast.success(t('bots.saveSuccess'));
} catch (error) {
const message =
typeof error === 'object' && error && 'msg' in error
? String((error as { msg?: string }).msg || '')
: '';
toast.error(t('bots.saveError') + message);
showBotError(error, t('bots.saveError'), t);
throw error;
}
}
+31
View File
@@ -0,0 +1,31 @@
import type { TFunction } from 'i18next';
import { toast } from 'sonner';
export function showBotError(error: unknown, title: string, t: TFunction) {
const detail =
error && typeof error === 'object'
? (error as {
code?: string;
msg?: string;
message?: string;
request_id?: string;
})
: {};
const message = detail.msg || detail.message || '';
const description =
detail.code === 'internal_error'
? [
t('bots.internalErrorHint'),
detail.request_id &&
t('bots.errorReference', { id: detail.request_id }),
]
.filter(Boolean)
.join('\n')
: message;
toast.error(
detail.code === 'bot_apply_failed'
? t('bots.applyFailed')
: title.replace(/[:]\s*$/, ''),
{ description, duration: 10000 },
);
}
@@ -1,3 +1,4 @@
import { showBotError } from '../../bot-error';
import React, {
forwardRef,
useEffect,
@@ -413,7 +414,7 @@ const BotForm = forwardRef<BotFormHandle, BotFormProps>(function BotForm(
toast.success(t('bots.saveSuccess'));
})
.catch((err) => {
toast.error(t('bots.saveError') + err.msg);
showBotError(err, t('bots.saveError'), t);
})
.finally(() => {
setIsLoading(false);
@@ -438,7 +439,10 @@ const BotForm = forwardRef<BotFormHandle, BotFormProps>(function BotForm(
onNewBotCreated(res.uuid);
})
.catch((err) => {
toast.error(t('bots.createError') + err.msg);
showBotError(err, t('bots.createError'), t);
if (err.code === 'bot_apply_failed' && err.data?.uuid) {
onNewBotCreated(err.data.uuid);
}
})
.finally(() => {
setIsLoading(false);