openlark_application/common/
api_utils.rs1use openlark_core::{SDKResult, error};
5
6pub fn extract_response_data<T>(
16 response: openlark_core::api::Response<T>,
17 context: &str,
18) -> SDKResult<T> {
19 response.data.ok_or_else(|| {
20 error::validation_error(
21 format!("{context}响应数据为空").as_str(),
22 "服务器没有返回有效的数据",
23 )
24 })
25}
26
27pub fn serialize_params<T: serde::Serialize>(
37 params: &T,
38 context: &str,
39) -> SDKResult<serde_json::Value> {
40 serde_json::to_value(params).map_err(|e| {
41 error::validation_error(
42 format!("{context}参数序列化失败").as_str(),
43 format!("无法序列化请求参数: {e}").as_str(),
44 )
45 })
46}