Pipeline: Avoid spamming stderr when not needed
This commit add a new DataError Variant for feeds that return 304.
Its expected behaviror and the current API of Source::into_feed
is kinda limiting the return type to make it easier to handle.
Up till now 304 was returning an Error to early return. Ideally
Source::into_feed will return a Multi variant Result Enum.
example:
enum FeedResult {
Ok(Success(feed)),
Ok(NotModified),
Err(err),
}
Hopefully in a refactor in the near Future™
Till then we will just have to match and ignore
DataError::FeedNotModified.
This commit is contained in:
parent
ca6996e53a
commit
da361d0cb9
@ -65,6 +65,8 @@ pub enum DataError {
|
||||
HttpStatusGeneral(HttpStatusError),
|
||||
#[fail(display = "Source redirects to a new url")]
|
||||
FeedRedirect(Source),
|
||||
#[fail(display = "Feed is up to date")]
|
||||
FeedNotModified(Source),
|
||||
#[fail(
|
||||
display = "Error occured while Parsing an Episode. Reason: {}",
|
||||
reason
|
||||
|
||||
@ -144,7 +144,10 @@ impl Source {
|
||||
};
|
||||
|
||||
match code {
|
||||
StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)),
|
||||
StatusCode::NotModified => {
|
||||
info!("304: Source, (id: {}), is up to date", self.id());
|
||||
return Err(DataError::FeedNotModified(self));
|
||||
}
|
||||
StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => {
|
||||
warn!("Feed was moved permanently.");
|
||||
self = self.update_url(&res)?;
|
||||
|
||||
@ -38,8 +38,13 @@ where
|
||||
})
|
||||
// the stream will stop at the first error so
|
||||
// we ensure that everything will succeded regardless.
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.then(|_| ok::<(), DataError>(()))
|
||||
.map_err(|err| {
|
||||
match err {
|
||||
// Avoid spamming the stderr when its not an eactual error
|
||||
DataError::FeedNotModified(_) => (),
|
||||
_ => error!("Error: {}", err),
|
||||
}
|
||||
}).then(|_| ok::<(), DataError>(()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user