From 4ca9027cd69b2258f8e8778953a240659a653cb1 Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 15 May 2026 15:25:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=81=94=E5=90=88=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=20=E2=80=94=20=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=20+=20request=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E5=8F=96=20+=20copilot=20=E8=A7=A3?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ISSUE-APPOINTMENT-001: 后端 DoctorNotFound 改为 Validation 错误(400) + 改善错误消息"所选医生暂无医护档案,请联系管理员" + 小程序预约创建 catch 传递实际错误消息(不再硬编码"预约失败") + 小程序 request.ts 提取后端 message 字段作为用户提示 - copilot API: listInsights/listRules/getPatientRisk 补齐 data.data 解包 - 移除 error.rs 重复的 AppointmentNotFound 分支 --- .../src/pages/appointment/create/index.tsx | 5 +++-- apps/miniprogram/src/services/request.ts | 6 ++++-- apps/web/src/api/copilot.ts | 15 +++++++++------ crates/erp-health/src/error.rs | 9 +++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/miniprogram/src/pages/appointment/create/index.tsx b/apps/miniprogram/src/pages/appointment/create/index.tsx index f2df209..4b5fd12 100644 --- a/apps/miniprogram/src/pages/appointment/create/index.tsx +++ b/apps/miniprogram/src/pages/appointment/create/index.tsx @@ -130,8 +130,9 @@ export default function AppointmentCreate() { } catch { /* 用户拒绝 */ } } safeSetTimeout(() => Taro.navigateBack(), 1500); - } catch { - Taro.showToast({ title: '预约失败', icon: 'none' }); + } catch (err: any) { + const msg = err?.message || '预约失败'; + Taro.showToast({ title: msg.length > 20 ? msg.slice(0, 20) : msg, icon: 'none' }); } finally { setLoading(false); } diff --git a/apps/miniprogram/src/services/request.ts b/apps/miniprogram/src/services/request.ts index 2942745..b3c4b17 100644 --- a/apps/miniprogram/src/services/request.ts +++ b/apps/miniprogram/src/services/request.ts @@ -278,9 +278,11 @@ async function request(method: string, path: string, data?: unknown, timeout? throw new Error('服务器错误'); } - const body = res.data as ApiResponse; + const body = res.data as ApiResponse & { message?: string }; if (!body.success) { - const userMsg = body.error_code ? (ERROR_CODE_MAP[body.error_code] || '操作失败,请稍后重试') : '操作失败,请稍后重试'; + const userMsg = body.error_code + ? (ERROR_CODE_MAP[body.error_code] || body.message || '操作失败,请稍后重试') + : (body.message || '操作失败,请稍后重试'); throw new Error(userMsg); } return body.data as T; diff --git a/apps/web/src/api/copilot.ts b/apps/web/src/api/copilot.ts index efe53a2..535e48e 100644 --- a/apps/web/src/api/copilot.ts +++ b/apps/web/src/api/copilot.ts @@ -36,18 +36,20 @@ export interface CopilotInsight { // --- API Functions --- -export function getPatientRisk(patientId: string) { - return client.get(`/copilot/patients/${patientId}/risk`); +export async function getPatientRisk(patientId: string) { + const { data } = await client.get<{ success: boolean; data: RiskScore }>(`/copilot/patients/${patientId}/risk`); + return data.data; } -export function listInsights(params: { +export async function listInsights(params: { patient_id?: string; insight_type?: string; severity?: string; page?: number; page_size?: number; }) { - return client.get>('/copilot/insights', { params }); + const { data } = await client.get<{ success: boolean; data: PaginatedResponse }>('/copilot/insights', { params }); + return data.data; } export function dismissInsight(id: string) { @@ -58,6 +60,7 @@ export function listAlerts(params?: { severity?: string; page?: number; page_siz return listInsights({ insight_type: 'anomaly', ...params }); } -export function listRules(params?: { page?: number; page_size?: number }) { - return client.get>>('/copilot/rules', { params }); +export async function listRules(params?: { page?: number; page_size?: number }) { + const { data } = await client.get<{ success: boolean; data: PaginatedResponse> }>('/copilot/rules', { params }); + return data.data; } diff --git a/crates/erp-health/src/error.rs b/crates/erp-health/src/error.rs index f8be9b0..fa0d751 100644 --- a/crates/erp-health/src/error.rs +++ b/crates/erp-health/src/error.rs @@ -8,7 +8,7 @@ pub enum HealthError { #[error("患者不存在")] PatientNotFound, - #[error("医护档案不存在")] + #[error("所选医生暂无医护档案,请联系管理员")] DoctorNotFound, #[error("预约不存在")] @@ -124,9 +124,10 @@ impl From for AppError { fn from(err: HealthError) -> Self { match err { HealthError::Validation(s) => AppError::Validation(s), - HealthError::PatientNotFound - | HealthError::DoctorNotFound - | HealthError::AppointmentNotFound + HealthError::PatientNotFound | HealthError::DoctorNotFound => { + AppError::Validation(err.to_string()) + } + HealthError::AppointmentNotFound | HealthError::ScheduleNotFound | HealthError::VitalSignsNotFound | HealthError::LabReportNotFound