pub enum LarkAPIError {
IOErr(String),
IllegalParamError(String),
DeserializeError(String),
RequestError(String),
UrlParseError(String),
ApiError {
code: i32,
message: String,
request_id: Option<String>,
},
MissingAccessToken,
BadRequest(String),
DataError(String),
APIError {
code: i32,
msg: String,
error: Option<String>,
},
}Expand description
飞书开放平台API错误类型
包含所有可能的API调用错误,提供详细的错误信息和处理建议。 支持错误分类、重试判断和用户友好的错误消息。
§错误类型分类
- 网络错误: RequestError, IOErr, UrlParseError
- 数据错误: DeserializeError, DataError
- 参数错误: IllegalParamError, BadRequest
- API错误: ApiError, APIError
- 认证错误: MissingAccessToken
§错误处理示例
use open_lark::core::error::LarkAPIError;
fn handle_api_error(error: LarkAPIError) {
match error {
LarkAPIError::MissingAccessToken => {
println!("请检查应用凭据配置");
}
LarkAPIError::ApiError { code, message, .. } if code == 403 => {
println!("权限不足: {}", message);
}
err if err.is_retryable() => {
println!("网络错误,可以重试: {}", err.user_friendly_message());
}
_ => {
println!("操作失败: {}", error.user_friendly_message());
}
}
}§最佳实践
- 使用
is_retryable()判断是否可以重试 - 使用
user_friendly_message()获取用户友好的错误提示 - 使用
is_permission_error()检查权限相关错误
Variants§
IOErr(String)
输入输出错误
通常由文件操作、网络IO等底层操作失败引起。
IllegalParamError(String)
非法参数错误
当传入的参数不符合API要求时抛出,如无效的ID格式、超出范围的值等。
DeserializeError(String)
JSON反序列化错误
当API响应的JSON格式无法解析为预期的数据结构时发生。
RequestError(String)
HTTP请求失败
网络请求层面的错误,如连接超时、DNS解析失败等。通常可以重试。
UrlParseError(String)
URL解析错误
当构建的API请求URL格式不正确时发生。
ApiError
增强的API错误
包含错误码、消息和请求ID的完整错误信息,便于调试和问题追踪。
MissingAccessToken
缺少访问令牌
当API调用需要认证但未提供有效的访问令牌时发生。
BadRequest(String)
错误的请求
请求格式或内容不符合API规范。
DataError(String)
数据处理错误
数据验证、转换或处理过程中发生的错误。
APIError
标准API响应错误
飞书开放平台返回的标准错误响应,包含完整的错误信息。
Implementations§
Source§impl LarkAPIError
impl LarkAPIError
Sourcepub fn api_error<M: Into<String>>(
code: i32,
message: M,
request_id: Option<String>,
) -> Self
pub fn api_error<M: Into<String>>( code: i32, message: M, request_id: Option<String>, ) -> Self
Sourcepub fn illegal_param<T: Into<String>>(message: T) -> Self
pub fn illegal_param<T: Into<String>>(message: T) -> Self
Sourcepub fn is_permission_error(&self) -> bool
pub fn is_permission_error(&self) -> bool
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Sourcepub fn user_friendly_message(&self) -> String
pub fn user_friendly_message(&self) -> String
Trait Implementations§
Source§impl Clone for LarkAPIError
impl Clone for LarkAPIError
Source§impl Debug for LarkAPIError
impl Debug for LarkAPIError
Source§impl Display for LarkAPIError
impl Display for LarkAPIError
Source§impl Error for LarkAPIError
impl Error for LarkAPIError
1.30.0 · 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 LarkAPIError
impl From<Error> for LarkAPIError
Source§impl From<Error> for LarkAPIError
impl From<Error> for LarkAPIError
Source§impl From<Error> for LarkAPIError
impl From<Error> for LarkAPIError
Source§impl From<ParseError> for LarkAPIError
impl From<ParseError> for LarkAPIError
Source§fn from(err: ParseError) -> Self
fn from(err: ParseError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for LarkAPIError
impl RefUnwindSafe for LarkAPIError
impl Send for LarkAPIError
impl Sync for LarkAPIError
impl Unpin for LarkAPIError
impl UnwindSafe for LarkAPIError
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.