推进 server-rs DDD 分层与新接口接线
This commit is contained in:
@@ -1,3 +1,61 @@
|
||||
//! AI 领域错误过渡落位。
|
||||
//!
|
||||
//! 错误必须可被 HTTP adapter 和 SpacetimeDB adapter 显式映射,不能直接绑定状态码。
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum AiTaskFieldError {
|
||||
MissingTaskId,
|
||||
MissingOwnerUserId,
|
||||
MissingRequestLabel,
|
||||
MissingSourceModule,
|
||||
MissingStageBlueprints,
|
||||
DuplicateStageBlueprint,
|
||||
MissingReferenceId,
|
||||
MissingChunkText,
|
||||
InvalidSequence,
|
||||
MissingFailureMessage,
|
||||
MissingStage,
|
||||
InvalidTaskState,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum AiTaskServiceError {
|
||||
Field(AiTaskFieldError),
|
||||
TaskAlreadyExists,
|
||||
TaskNotFound,
|
||||
StageNotFound,
|
||||
Store(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for AiTaskFieldError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::MissingTaskId => f.write_str("ai_task.task_id 不能为空"),
|
||||
Self::MissingOwnerUserId => f.write_str("ai_task.owner_user_id 不能为空"),
|
||||
Self::MissingRequestLabel => f.write_str("ai_task.request_label 不能为空"),
|
||||
Self::MissingSourceModule => f.write_str("ai_task.source_module 不能为空"),
|
||||
Self::MissingStageBlueprints => f.write_str("ai_task.stages 至少需要一个有效阶段"),
|
||||
Self::DuplicateStageBlueprint => f.write_str("ai_task.stages 不能包含重复阶段"),
|
||||
Self::MissingReferenceId => f.write_str("ai_result_reference.reference_id 不能为空"),
|
||||
Self::MissingChunkText => f.write_str("ai_text_chunk.delta_text 不能为空"),
|
||||
Self::InvalidSequence => f.write_str("ai_text_chunk.sequence 必须大于 0"),
|
||||
Self::MissingFailureMessage => f.write_str("ai_task.failure_message 不能为空"),
|
||||
Self::MissingStage => f.write_str("ai_task.stage 不存在"),
|
||||
Self::InvalidTaskState => f.write_str("当前 ai_task 状态不允许执行该操作"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for AiTaskFieldError {}
|
||||
|
||||
impl fmt::Display for AiTaskServiceError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Field(error) => write!(f, "{error}"),
|
||||
Self::TaskAlreadyExists => f.write_str("ai_task 已存在,不能重复创建"),
|
||||
Self::TaskNotFound => f.write_str("ai_task 不存在"),
|
||||
Self::StageNotFound => f.write_str("ai_task.stage 不存在"),
|
||||
Self::Store(message) => f.write_str(message),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for AiTaskServiceError {}
|
||||
|
||||
Reference in New Issue
Block a user