From 609fc6581697ab82876bd2712c52467ae6e7ea0e Mon Sep 17 00:00:00 2001 From: jane400 Date: Thu, 22 Aug 2024 12:42:34 +0200 Subject: [PATCH] fix: tracking: parse rate limited response Technically NetworkFetch isn't intended for this. /shrug for now --- libpaket/src/tracking.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libpaket/src/tracking.rs b/libpaket/src/tracking.rs index 0def858..36495c2 100644 --- a/libpaket/src/tracking.rs +++ b/libpaket/src/tracking.rs @@ -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, + sendungen: Option>, // TODO: parse RECEIVE_MERGED_SHIPMENTS, what is that? //merged_anonymous_shipment_list_ids: Option>, is_rate_limited: bool, @@ -313,7 +313,7 @@ pub struct Shipment { pub needs_plz: bool, pub quelle: SendungsQuelle, - + // probably not optional pub international: Option, // probably not optional @@ -388,15 +388,19 @@ impl From for Shipment { } } -impl From for Vec { +impl From for LibraryResult> { 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 } }