fix: tracking: parse rate limited response

Technically NetworkFetch isn't intended for this. /shrug for now
This commit is contained in:
jane400 2024-08-22 12:42:34 +02:00 committed by jane400
parent 290faff5c2
commit 609fc65816

View file

@ -44,7 +44,7 @@ impl crate::WebClient {
};
let resp = parse_json_response!(res, Response);
Ok(resp.into())
resp.into()
}
pub async fn tracking_shipment(
@ -62,7 +62,7 @@ impl crate::WebClient {
);
let resp = parse_json_response!(res, Response);
Ok(resp.into())
resp.into()
}
}
@ -228,7 +228,7 @@ struct Sendung {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct Response {
sendungen: Vec<Sendung>,
sendungen: Option<Vec<Sendung>>,
// TODO: parse RECEIVE_MERGED_SHIPMENTS, what is that?
//merged_anonymous_shipment_list_ids: Option<Vec<()>>,
is_rate_limited: bool,
@ -388,15 +388,19 @@ impl From<Sendung> for Shipment {
}
}
impl From<Response> for Vec<Shipment> {
impl From<Response> for LibraryResult<Vec<Shipment>> {
fn from(value: Response) -> Self {
let mut arr = Vec::new();
if value.is_rate_limited {
Err(crate::LibraryError::NetworkFetch)
} else {
let mut arr = Vec::new();
for item in value.sendungen {
arr.push(item.into());
for item in value.sendungen.unwrap() {
arr.push(item.into());
}
Ok(arr)
}
arr
}
}