fix: 联合调试问题修复 — 预约错误提示 + request 错误提取 + copilot 解包

- ISSUE-APPOINTMENT-001: 后端 DoctorNotFound 改为 Validation 错误(400)
  + 改善错误消息"所选医生暂无医护档案,请联系管理员"
  + 小程序预约创建 catch 传递实际错误消息(不再硬编码"预约失败")
  + 小程序 request.ts 提取后端 message 字段作为用户提示
- copilot API: listInsights/listRules/getPatientRisk 补齐 data.data 解包
- 移除 error.rs 重复的 AppointmentNotFound 分支
This commit is contained in:
iven
2026-05-15 15:25:26 +08:00
parent 057d9b5896
commit 4ca9027cd6
4 changed files with 21 additions and 14 deletions

View File

@@ -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);
}

View File

@@ -278,9 +278,11 @@ async function request<T>(method: string, path: string, data?: unknown, timeout?
throw new Error('服务器错误');
}
const body = res.data as ApiResponse<T>;
const body = res.data as ApiResponse<T> & { 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;

View File

@@ -36,18 +36,20 @@ export interface CopilotInsight {
// --- API Functions ---
export function getPatientRisk(patientId: string) {
return client.get<RiskScore>(`/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<PaginatedResponse<CopilotInsight>>('/copilot/insights', { params });
const { data } = await client.get<{ success: boolean; data: PaginatedResponse<CopilotInsight> }>('/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<PaginatedResponse<Record<string, unknown>>>('/copilot/rules', { params });
export async function listRules(params?: { page?: number; page_size?: number }) {
const { data } = await client.get<{ success: boolean; data: PaginatedResponse<Record<string, unknown>> }>('/copilot/rules', { params });
return data.data;
}

View File

@@ -8,7 +8,7 @@ pub enum HealthError {
#[error("患者不存在")]
PatientNotFound,
#[error("医护档案不存在")]
#[error("所选医生暂无医护档案,请联系管理员")]
DoctorNotFound,
#[error("预约不存在")]
@@ -124,9 +124,10 @@ impl From<HealthError> 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