pub enum ApiError {
Http {
status: StatusCode,
text: String,
},
Reqwest(Error),
Json(Error),
EventSource(String),
Io(Error),
Other(String),
Unknown,
}Expand description
统一的错误类型,覆盖常见的错误来源并保留一个通用字符串变体用于快速转换。
Variants§
Http
HTTP 层面的失败(当我们想保留状态码与响应文本时使用)
Reqwest(Error)
reqwest 网络/请求错误
Json(Error)
serde_json 解析/序列化错误
EventSource(String)
EventSource / SSE 处理错误(来自 eventsource-stream crate)
以字符串形式保存错误信息(避免直接依赖具体 crate 的错误类型签名)
Io(Error)
IO 错误(保底)
Other(String)
通用字符串错误(方便从 String / &str 直接转换)
Unknown
未知或占位错误
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn http_error(status: StatusCode, text: impl Into<String>) -> Self
pub fn http_error(status: StatusCode, text: impl Into<String>) -> Self
创建一个 Http 变体的快捷方法
Trait Implementations§
Source§impl Error for ApiError
impl Error for ApiError
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()
Auto Trait Implementations§
impl Freeze for ApiError
impl !RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl !UnwindSafe for ApiError
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.