feat(skills): enhance error messages with i18n support
- Add structured error format with error codes and context - Create skillErrorParser to format errors for user-friendly display - Add comprehensive i18n keys for all skill-related errors (zh/en) - Extend download timeout from 15s to 60s to reduce false positives - Fix: Pass correct error title based on operation context (load/install/uninstall) Error improvements: - SKILL_NOT_FOUND: Show skill directory name - DOWNLOAD_TIMEOUT: Display repo info and timeout duration with network suggestion - DOWNLOAD_FAILED: Show HTTP status code with specific suggestions (403/404/429) - SKILL_DIR_NOT_FOUND: Show full path with URL check suggestion - EMPTY_ARCHIVE: Suggest checking repository URL Users will now see detailed error messages instead of generic "Error".
This commit is contained in:
@@ -94,3 +94,28 @@ impl From<AppError> for String {
|
||||
err.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// 格式化为 JSON 错误字符串,前端可解析为结构化错误
|
||||
pub fn format_skill_error(
|
||||
code: &str,
|
||||
context: &[(&str, &str)],
|
||||
suggestion: Option<&str>,
|
||||
) -> String {
|
||||
use serde_json::json;
|
||||
|
||||
let mut ctx_map = serde_json::Map::new();
|
||||
for (key, value) in context {
|
||||
ctx_map.insert(key.to_string(), json!(value));
|
||||
}
|
||||
|
||||
let error_obj = json!({
|
||||
"code": code,
|
||||
"context": ctx_map,
|
||||
"suggestion": suggestion,
|
||||
});
|
||||
|
||||
serde_json::to_string(&error_obj).unwrap_or_else(|_| {
|
||||
// 如果 JSON 序列化失败,返回简单格式
|
||||
format!("ERROR:{}", code)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user