openlark_client/client/
error_handling.rs1use super::Client;
2use crate::{Result, error::with_operation_context};
3
4pub trait ClientErrorHandling {
6 fn handle_error<T>(&self, result: Result<T>, operation: &str) -> Result<T>;
8 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}