Skip to main content

openlark_client/client/
error_handling.rs

1use super::Client;
2use crate::{Result, error::with_operation_context};
3
4/// 客户端错误处理扩展特征
5pub trait ClientErrorHandling {
6    /// 处理错误并添加客户端上下文
7    fn handle_error<T>(&self, result: Result<T>, operation: &str) -> Result<T>;
8    /// 处理异步错误并添加客户端上下文
9    fn handle_async_error<'a, T, F>(
10        &'a self,
11        f: F,
12        operation: &'a str,
13    ) -> impl std::future::Future<Output = Result<T>> + Send + 'a
14    where
15        T: Send + 'a,
16        F: std::future::Future<Output = Result<T>> + Send + 'a;
17}
18
19impl ClientErrorHandling for Client {
20    fn handle_error<T>(&self, result: Result<T>, operation: &str) -> Result<T> {
21        with_operation_context(result, operation, "Client")
22    }
23
24    async fn handle_async_error<'a, T, F>(&'a self, f: F, operation: &'a str) -> Result<T>
25    where
26        T: Send + 'a,
27        F: std::future::Future<Output = Result<T>> + Send + 'a,
28    {
29        let result = f.await;
30        with_operation_context(result, operation, "Client")
31    }
32}