Files
hms/crates/erp-health/src/error.rs
iven bf8bcdbd5d fix: E2E 测试发现的后端 BUG 修复 — 限流拆分 + 积分查询 + 错误码修正
- 拆分 refresh token 限流为独立中间件(30次/分 vs 登录5次/分)
- 修复积分 recent-activity 500:JOIN 通过 points_account 中间表
- 修复患者/医生不存在返回 400 → 正确的 404 NotFound
2026-05-15 22:58:02 +08:00

193 lines
5.2 KiB
Rust

use erp_core::error::AppError;
#[derive(Debug, thiserror::Error)]
pub enum HealthError {
#[error("{0}")]
Validation(String),
#[error("患者不存在")]
PatientNotFound,
#[error("所选医生暂无医护档案,请联系管理员")]
DoctorNotFound,
#[error("预约不存在")]
AppointmentNotFound,
#[error("排班不存在")]
ScheduleNotFound,
#[error("体征记录不存在")]
VitalSignsNotFound,
#[error("化验报告不存在")]
LabReportNotFound,
#[error("日常监测记录不存在")]
DailyMonitoringNotFound,
#[error("积分规则不存在")]
PointsRuleNotFound,
#[error("兑换商品不存在")]
PointsProductNotFound,
#[error("兑换订单不存在")]
PointsOrderNotFound,
#[error("线下活动不存在")]
OfflineEventNotFound,
#[error("健康档案不存在")]
HealthRecordNotFound,
#[error("家庭成员不存在")]
FamilyMemberNotFound,
#[error("标签不存在")]
TagNotFound,
#[error("排班已满,无法预约")]
ScheduleFull,
#[error("随访任务不存在")]
FollowUpTaskNotFound,
#[error("会话不存在")]
ConsultationNotFound,
#[error("文章不存在")]
ArticleNotFound,
#[error("危急值阈值不存在")]
ThresholdNotFound,
#[error("知情同意记录不存在")]
ConsentNotFound,
#[error("设备绑定不存在")]
DeviceNotFound,
#[error("告警规则不存在")]
AlertRuleNotFound,
#[error("告警记录不存在")]
AlertNotFound,
#[error("随访模板不存在")]
FollowUpTemplateNotFound,
#[error("危急值告警不存在")]
CriticalAlertNotFound,
#[error("药物提醒不存在")]
MedicationReminderNotFound,
#[error("护理计划不存在")]
CarePlanNotFound,
#[error("护理计划条目不存在")]
CarePlanItemNotFound,
#[error("护理计划预后不存在")]
CarePlanOutcomeNotFound,
#[error("班次不存在")]
ShiftNotFound,
#[error("患者分配不存在")]
PatientAssignmentNotFound,
#[error("交接记录不存在")]
HandoffLogNotFound,
#[error("媒体文件不存在")]
MediaNotFound,
#[error("媒体文件夹不存在")]
MediaFolderNotFound,
#[error("轮播图不存在")]
BannerNotFound,
#[error("状态转换无效: {0}")]
InvalidStatusTransition(String),
#[error("版本冲突: 数据已被其他操作修改,请刷新后重试")]
VersionMismatch,
#[error("数据库操作失败: {0}")]
DbError(String),
#[error("权限不足: {0}")]
Forbidden(String),
}
impl From<HealthError> for AppError {
fn from(err: HealthError) -> Self {
match err {
HealthError::Validation(s) => AppError::Validation(s),
HealthError::PatientNotFound | HealthError::DoctorNotFound => {
AppError::NotFound(err.to_string())
}
HealthError::AppointmentNotFound
| HealthError::ScheduleNotFound
| HealthError::VitalSignsNotFound
| HealthError::LabReportNotFound
| HealthError::HealthRecordNotFound
| HealthError::FamilyMemberNotFound
| HealthError::TagNotFound
| HealthError::FollowUpTaskNotFound
| HealthError::ConsultationNotFound
| HealthError::ArticleNotFound
| HealthError::PointsRuleNotFound
| HealthError::PointsProductNotFound
| HealthError::PointsOrderNotFound
| HealthError::OfflineEventNotFound
| HealthError::DailyMonitoringNotFound
| HealthError::ThresholdNotFound
| HealthError::ConsentNotFound
| HealthError::AlertRuleNotFound
| HealthError::DeviceNotFound
| HealthError::AlertNotFound
| HealthError::FollowUpTemplateNotFound
| HealthError::CriticalAlertNotFound
| HealthError::MedicationReminderNotFound
| HealthError::CarePlanNotFound
| HealthError::CarePlanItemNotFound
| HealthError::CarePlanOutcomeNotFound
| HealthError::ShiftNotFound
| HealthError::PatientAssignmentNotFound
| HealthError::HandoffLogNotFound
| HealthError::MediaNotFound
| HealthError::MediaFolderNotFound
| HealthError::BannerNotFound => AppError::NotFound(err.to_string()),
HealthError::ScheduleFull => AppError::Validation(err.to_string()),
HealthError::InvalidStatusTransition(s) => AppError::Validation(s),
HealthError::VersionMismatch => AppError::VersionMismatch,
HealthError::Forbidden(msg) => AppError::Forbidden(msg),
HealthError::DbError(_) => AppError::Internal(err.to_string()),
}
}
}
impl From<sea_orm::DbErr> for HealthError {
fn from(err: sea_orm::DbErr) -> Self {
HealthError::DbError(err.to_string())
}
}
impl From<AppError> for HealthError {
fn from(err: AppError) -> Self {
HealthError::Validation(err.to_string())
}
}
impl From<String> for HealthError {
fn from(err: String) -> Self {
HealthError::Validation(err)
}
}
pub type HealthResult<T> = Result<T, HealthError>;