u-sdk 0.6.1

Some useful SDKs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use super::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() {
        let body = resp.text().await.unwrap_or_default();
        return Err(Error::API { code: status, body });
    }

    let json = resp.json::<T>().await?;
    Ok(json)
}