Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(datasource): improve error handling and user feedback in DataSource components
wizardchen36dac0120a3c
diff --git a/frontend/src/utils/request.ts b/frontend/src/utils/request.tsindex c890c3898..e5df898d5 100644--- a/frontend/src/utils/request.ts+++ b/frontend/src/utils/request.ts@@ -82,7 +82,7 @@ instance.interceptors.response.use((response) => {// 根据业务状态码处理逻辑const { status, data } = response;- if (status === 200 || status === 201) {+ if (status >= 200 && status < 300) {return data;} else {return Promise.reject(data);@@ -190,9 +190,18 @@ instance.interceptors.response.use(// 将HTTP状态码一并抛出,方便上层判断401等场景// 后端返回格式: { success: false, error: { code, message, details } }// 提取 error.message 作为顶层 message,方便前端使用 error?.message 获取- const errorMessage = typeof data === 'object' && data?.error?.message- ? data.error.message- : (typeof data === 'object' ? data?.message : data);+ let errorMessage: string | undefined;+ if (typeof data === 'object') {+ if (typeof data?.error === 'string') {+ errorMessage = data.error;+ } else if (data?.error?.message) {+ errorMessage = data.error.message;+ } else {+ errorMessage = data?.message;+ }+ } else if (typeof data === 'string') {+ errorMessage = data;+ }return Promise.reject({status,message: errorMessage,diff --git a/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue b/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vueindex 1af12c52f..114e3d989 100644--- a/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue+++ b/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue@@ -207,7 +207,7 @@ async function testConnection() {MessagePlugin.success(t('datasource.testSuccess'))} catch (e: any) {testResult.value = 'error'- testErrorMsg.value = e?.response?.data?.error || e?.message || ''+ testErrorMsg.value = e?.message || e?.error || ''MessagePlugin.error(t('datasource.testFailed'))}testing.value = false@@ -234,8 +234,8 @@ async function loadResources() {const res = await listResources(tempDsId.value)resources.value = res?.data || res || []- } catch {- MessagePlugin.error(t('datasource.resourceLoadFailed'))+ } catch (e: any) {+ MessagePlugin.error(e?.message || e?.error || t('datasource.resourceLoadFailed'))}loadingResources.value = false}@@ -300,7 +300,7 @@ async function handleSubmit() {emit('saved')visible.value = false} catch (e: any) {- MessagePlugin.error(e?.message || t('datasource.saveFailed'))+ MessagePlugin.error(e?.message || e?.error || t('datasource.saveFailed'))}submitting.value = false}@@ -478,12 +478,18 @@ const stepTitles = computed(() => [<t-button variant="outline" :loading="testing" @click="testConnection">{{ t('datasource.testConnection') }}</t-button>- <span v-if="testResult === 'success'" class="test-ok">{{ t('datasource.connected') }}</span>- <span v-if="testResult === 'error'" class="test-fail">- {{ t('datasource.connectionFailed') }}- <span v-if="testErrorMsg" class="test-error-detail">- {{ testErrorMsg }}</span>+ <span v-if="testResult === 'success'" class="test-ok">+ <t-icon name="check-circle-filled" size="14px" />+ {{ t('datasource.connected') }}</span></div>+ <div v-if="testResult === 'error'" class="test-error-box">+ <t-icon name="error-circle-filled" size="16px" />+ <div class="test-error-content">+ <span class="test-error-title">{{ t('datasource.connectionFailed') }}</span>+ <span v-if="testErrorMsg" class="test-error-detail">{{ testErrorMsg }}</span>+ </div>+ </div><div class="ds-dialog-footer"><t-button variant="outline" @click="step = 0" v-if="!isEdit">{{ t('datasource.back') }}</t-button>@@ -799,9 +805,38 @@ const stepTitles = computed(() => [.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--td-text-color-primary); }.form-tip { font-size: 12px; color: var(--td-text-color-placeholder); margin: 4px 0 12px; }.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }-.test-ok { color: #00a870; font-size: 13px; }-.test-fail { color: #e34d59; font-size: 13px; }-.test-error-detail { font-size: 11px; color: var(--td-text-color-placeholder); }+.test-ok { color: var(--td-success-color); font-size: 13px; display: flex; align-items: center; gap: 4px; }++.test-error-box {+ display: flex;+ align-items: flex-start;+ gap: 8px;+ margin-top: 10px;+ padding: 10px 14px;+ border-radius: 8px;+ background: var(--td-error-color-1);+ color: var(--td-error-color);+ font-size: 13px;+ line-height: 20px;+}++.test-error-content {+ display: flex;+ flex-direction: column;+ gap: 2px;+ min-width: 0;+}++.test-error-title {+ font-weight: 500;+}++.test-error-detail {+ font-size: 12px;+ color: var(--td-error-color);+ opacity: 0.8;+ word-break: break-word;+}.ds-dialog-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--td-border-level-2-color); }diff --git a/frontend/src/views/knowledge/settings/DataSourceSettings.vue b/frontend/src/views/knowledge/settings/DataSourceSettings.vueindex c3aa21747..67b16ec8c 100644--- a/frontend/src/views/knowledge/settings/DataSourceSettings.vue+++ b/frontend/src/views/knowledge/settings/DataSourceSettings.vue@@ -67,8 +67,8 @@ function handleDelete(ds: DataSource) {MessagePlugin.success(t('datasource.deleteSuccess'))await loadList()confirmDialog.hide()- } catch {- MessagePlugin.error(t('datasource.deleteFailed'))+ } catch (e: any) {+ MessagePlugin.error(e?.message || e?.error || t('datasource.deleteFailed'))}},})@@ -79,8 +79,8 @@ async function handleSync(ds: DataSource) {await triggerSync(ds.id)MessagePlugin.success(t('datasource.syncTriggered'))loadList()- } catch {- MessagePlugin.error(t('datasource.syncFailed'))+ } catch (e: any) {+ MessagePlugin.error(e?.message || e?.error || t('datasource.syncFailed'))}}@@ -89,8 +89,8 @@ async function handlePause(ds: DataSource) {await pauseDataSource(ds.id)MessagePlugin.success(t('datasource.paused'))loadList()- } catch {- MessagePlugin.error(t('datasource.pauseFailed'))+ } catch (e: any) {+ MessagePlugin.error(e?.message || e?.error || t('datasource.pauseFailed'))}}@@ -99,8 +99,8 @@ async function handleResume(ds: DataSource) {await resumeDataSource(ds.id)MessagePlugin.success(t('datasource.resumed'))loadList()- } catch {- MessagePlugin.error(t('datasource.resumeFailed'))+ } catch (e: any) {+ MessagePlugin.error(e?.message || e?.error || t('datasource.resumeFailed'))}}diff --git a/internal/application/service/datasource_service.go b/internal/application/service/datasource_service.goindex 212b9fa12..3eeb98a54 100644--- a/internal/application/service/datasource_service.go+++ b/internal/application/service/datasource_service.go@@ -281,11 +281,13 @@ func (s *DataSourceService) ManualSync(ctx context.Context, dsID string) (*types_, err = s.taskEnqueuer.Enqueue(task, asynq.Queue("default"))if err != nil {logger.Errorf(ctx, "failed to enqueue sync task: %v", err)- // Update sync log as failedsyncLog.Status = types.SyncLogStatusFailedsyncLog.FinishedAt = timePtr(time.Now())syncLog.ErrorMessage = err.Error()_ = s.syncLogRepo.Update(ctx, syncLog)+ ds.Status = types.DataSourceStatusError+ ds.ErrorMessage = fmt.Sprintf("Failed to enqueue sync: %v", err)+ _ = s.dsRepo.Update(ctx, ds)return nil, err}@@ -386,6 +388,9 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) esyncLog.FinishedAt = timePtr(time.Now())syncLog.ErrorMessage = fmt.Sprintf("Connector not found: %s", ds.Type)_ = s.syncLogRepo.Update(ctx, syncLog)+ ds.Status = types.DataSourceStatusError+ ds.ErrorMessage = syncLog.ErrorMessage+ _ = s.dsRepo.Update(ctx, ds)return err}@@ -397,6 +402,9 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) esyncLog.FinishedAt = timePtr(time.Now())syncLog.ErrorMessage = fmt.Sprintf("Invalid configuration: %v", err)_ = s.syncLogRepo.Update(ctx, syncLog)+ ds.Status = types.DataSourceStatusError+ ds.ErrorMessage = syncLog.ErrorMessage+ _ = s.dsRepo.Update(ctx, ds)return err}@@ -422,6 +430,9 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) esyncLog.FinishedAt = timePtr(time.Now())syncLog.ErrorMessage = fmt.Sprintf("Fetch failed: %v", fetchErr)_ = s.syncLogRepo.Update(ctx, syncLog)+ ds.Status = types.DataSourceStatusError+ ds.ErrorMessage = syncLog.ErrorMessage+ _ = s.dsRepo.Update(ctx, ds)return fetchErr}@@ -440,6 +451,9 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) esyncLog.FinishedAt = timePtr(time.Now())syncLog.ErrorMessage = fmt.Sprintf("Failed to get tenant info: %v", err)_ = s.syncLogRepo.Update(ctx, syncLog)+ ds.Status = types.DataSourceStatusError+ ds.ErrorMessage = syncLog.ErrorMessage+ _ = s.dsRepo.Update(ctx, ds)return err}ctx = context.WithValue(ctx, types.TenantInfoContextKey, tenant)