use serde::Deserialize;
use crate::error::{Result, UgosError};
#[derive(Debug, Deserialize)]
pub struct ApiResponse<T> {
pub code: i32,
pub msg: String,
pub data: T,
}
impl<T> ApiResponse<T> {
pub fn into_result(self) -> Result<T> {
match self.code {
200 => Ok(self.data),
1003 => Err(UgosError::AuthFailed),
1005 | 2052 => Err(UgosError::ParameterError(self.msg)),
1024 => Err(UgosError::LoginExpired),
2031 | 2063 | 3004 => Err(UgosError::OperationFailed(self.msg)),
9404 => Err(UgosError::AppNotFound(self.msg)),
9405 => Err(UgosError::AppServiceError(self.msg)),
code => Err(UgosError::Api {
code,
msg: self.msg,
}),
}
}
}
#[derive(Debug, Deserialize)]
pub struct ResultWrapper<T> {
pub result: T,
}