fix: tracking: parse rate limited response
Technically NetworkFetch isn't intended for this. /shrug for now
This commit is contained in:
parent
290faff5c2
commit
609fc65816
1 changed files with 14 additions and 10 deletions
|
@ -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,
|
||||
|
@ -313,7 +313,7 @@ pub struct Shipment {
|
|||
pub needs_plz: bool,
|
||||
|
||||
pub quelle: SendungsQuelle,
|
||||
|
||||
|
||||
// probably not optional
|
||||
pub international: Option<bool>,
|
||||
// probably not optional
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue