diff --git a/src/fetch.rs b/src/fetch.rs index bd185cd..96f02d7 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -1,8 +1,11 @@ -use std::{time::{Duration, Instant, SystemTime}, path::PathBuf}; +use std::{ + path::PathBuf, + time::{Duration, Instant, SystemTime}, +}; use futures::{sink::SinkExt, TryStreamExt}; use lazy_static::lazy_static; -use log::info; +use log::{info, warn}; use reqwest::Url; use scraper::Selector; use time::PrimitiveDateTime; @@ -94,11 +97,9 @@ impl PdfFetcher { .ok_or(Error::NotFound)?; let pdf_url = CHARTS_URL.join(pdf_href)?; - let origin_modtime = self - .client - .head(pdf_url.clone()) - .send() - .await? + let head_resp = self.client.head(pdf_url.clone()).send().await?; + + let origin_modtime = head_resp .headers() .get(reqwest::header::LAST_MODIFIED) .and_then(|val| { @@ -115,7 +116,13 @@ impl PdfFetcher { .zip(origin_modtime) .map_or(true, |(cache, origin)| origin > cache); - if outdated { + if !head_resp.status().is_success() { + warn!( + "MWRA server returned unexpected response, not fetching updated PDF: {:?}", + head_resp + ); + // Just use the cached PDF, assuming we have it + } else if outdated { info!("Cached PDF is outdated, downloading latest version"); let mut pdf_stream = self