pub enum MilkyError {
Show 13 variants
WebSocket(Box<Error>),
UrlParse(ParseError),
UnsupportedScheme(String),
Json(Error),
Io(Error),
ApiError {
message: String,
retcode: Option<i64>,
},
HttpApiError {
status: StatusCode,
message: String,
},
NotConnected,
Timeout,
UnexpectedResponse,
EchoMismatch,
Reqwest(Error),
Internal(String),
}Expand description
MilkyClient 操作中可能发生的错误枚举。
使用 thiserror::Error 宏来自动派生 std::error::Error trait 的实现,
并为每个错误变体提供用户友好的描述信息。
Variants§
WebSocket(Box<Error>)
WebSocket 通信过程中发生的错误。
通常由底层的 tokio-tungstenite 库引发。
UrlParse(ParseError)
URL 解析失败时发生的错误。 例如,当提供的服务器地址或API端点格式不正确时。
UnsupportedScheme(String)
当 URL 使用了不支持的协议方案(scheme)时发生的错误。 例如,客户端可能只支持 “http” 和 “https” (以及对应的 “ws”, “wss”)。
Json(Error)
JSON 序列化或反序列化过程中发生的错误。 这可能发生在构造API请求或解析API响应时。
Io(Error)
标准输入/输出 (I/O) 操作发生的错误。 例如,在读取配置文件或写入日志时可能发生。
ApiError
API 请求失败,通常表示服务器成功处理了请求但返回了一个业务逻辑上的错误。 例如,权限不足、参数错误等。
HttpApiError
HTTP API 请求返回了非成功状态码(例如 4xx, 5xx)。 这表示 HTTP 请求本身可能已发送,但服务器响应了一个 HTTP 错误。
NotConnected
表示 WebSocket 连接尚未建立或已经丢失。 尝试在未连接状态下进行需要连接的操作时可能发生。
Timeout
操作(如API请求)等待响应超时。
UnexpectedResponse
收到了非预期的响应类型。 例如,期望一个特定的JSON结构但收到了其他格式。
EchoMismatch
当请求中的 echo 字段与响应中的 echo 字段不匹配时发生。
用于验证异步请求和响应的对应关系。
Reqwest(Error)
底层 HTTP 请求库 (reqwest) 发生的错误。
例如,网络连接问题、DNS解析失败等。
Internal(String)
Trait Implementations§
Source§impl Debug for MilkyError
impl Debug for MilkyError
Source§impl Display for MilkyError
impl Display for MilkyError
Source§impl Error for MilkyError
impl Error for MilkyError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<Error> for MilkyError
impl From<Error> for MilkyError
Source§impl From<Error> for MilkyError
impl From<Error> for MilkyError
Source§impl From<Error> for MilkyError
impl From<Error> for MilkyError
Source§impl From<ParseError> for MilkyError
impl From<ParseError> for MilkyError
Source§fn from(source: ParseError) -> Self
fn from(source: ParseError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for MilkyError
impl !RefUnwindSafe for MilkyError
impl Send for MilkyError
impl Sync for MilkyError
impl Unpin for MilkyError
impl !UnwindSafe for MilkyError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.