u-sdk 0.6.1

Some useful SDKs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::translate::Error;

pub(crate) async fn parse_json_response<T: serde::de::DeserializeOwned>(
    resp: reqwest::Response,
) -> Result<T, Error> {
    let status = resp.status();
    if !status.is_success() {
        return Err(Error::RequestAPIFailed {
            code: status.to_string(),
            message: resp.text().await?,
        });
    }

    let data = resp.json().await?;
    Ok(data)
}