screeps_rust_api/
error.rs

1use reqwest::Error as ReqwestError;
2use serde_json::Error as SerdeError;
3use thiserror::Error;
4
5/// Screeps 错误类型
6#[derive(Error, Debug)]
7pub enum ScreepsError {
8    /// http 请求失败
9    #[error("HTTP request failed: {0}")]
10    Http(#[from] ReqwestError),
11
12    /// json 解析失败,可能是响应数据格式错误,或者是数据类型不匹配
13    #[error("JSON parse failed: {0}")]
14    Json(#[from] SerdeError),
15
16    /// api 接口报错
17    #[error("API error: {0}")]
18    Api(String),
19
20    /// auth 认证失败
21    #[error("Auth failed")]
22    Auth,
23
24    /// 配置错误
25    #[error("Invalid config: {0}")]
26    Config(String),
27}
28
29pub type ScreepsResult<T> = Result<T, ScreepsError>;