Close DDD refactor and remove generated asset proxy
This commit is contained in:
@@ -432,6 +432,14 @@ impl SpacetimeClientError {
|
||||
Self::Procedure(error.to_string())
|
||||
}
|
||||
|
||||
pub(crate) fn validation_failed(error: impl fmt::Display) -> Self {
|
||||
Self::Runtime(error.to_string())
|
||||
}
|
||||
|
||||
pub(crate) fn reducer_failed(message: String) -> Self {
|
||||
Self::Runtime(message)
|
||||
}
|
||||
|
||||
pub(crate) fn procedure_failed(message: Option<String>) -> Self {
|
||||
Self::Procedure(message.unwrap_or_else(|| "SpacetimeDB procedure 返回未知错误".to_string()))
|
||||
}
|
||||
@@ -515,3 +523,40 @@ impl fmt::Display for SpacetimeClientError {
|
||||
}
|
||||
|
||||
impl Error for SpacetimeClientError {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn procedure_failed_keeps_server_message_or_default() {
|
||||
assert_eq!(
|
||||
SpacetimeClientError::procedure_failed(Some("领域错误".to_string())).to_string(),
|
||||
"领域错误"
|
||||
);
|
||||
assert_eq!(
|
||||
SpacetimeClientError::procedure_failed(None).to_string(),
|
||||
"SpacetimeDB procedure 返回未知错误"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_snapshot_names_adapter_boundary() {
|
||||
assert_eq!(
|
||||
SpacetimeClientError::missing_snapshot("story session 快照").to_string(),
|
||||
"SpacetimeDB procedure 未返回story session 快照"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validation_and_reducer_failures_stay_runtime_classified() {
|
||||
assert!(matches!(
|
||||
SpacetimeClientError::validation_failed("字段缺失"),
|
||||
SpacetimeClientError::Runtime(_)
|
||||
));
|
||||
assert!(matches!(
|
||||
SpacetimeClientError::reducer_failed("状态非法".to_string()),
|
||||
SpacetimeClientError::Runtime(_)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user