DataError: Improve the FeedRedirect variant

This commit is contained in:
Jordan Petridis 2018-09-04 12:41:37 +03:00
parent a61bbc460f
commit ca6996e53a
No known key found for this signature in database
GPG Key ID: E8523968931763BE
2 changed files with 8 additions and 7 deletions

View File

@ -63,8 +63,8 @@ pub enum DataError {
Bail(String), Bail(String),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
HttpStatusGeneral(HttpStatusError), HttpStatusGeneral(HttpStatusError),
#[fail(display = "FIXME: This should be better")] #[fail(display = "Source redirects to a new url")]
F301(Source), FeedRedirect(Source),
#[fail( #[fail(
display = "Error occured while Parsing an Episode. Reason: {}", display = "Error occured while Parsing an Episode. Reason: {}",
reason reason

View File

@ -146,13 +146,14 @@ impl Source {
match code { match code {
StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)), StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)),
StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => { StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => {
error!("Feed was moved permanently."); warn!("Feed was moved permanently.");
self = self.update_url(&res)?; self = self.update_url(&res)?;
return Err(DataError::F301(self)); return Err(DataError::FeedRedirect(self));
} }
StatusCode::TemporaryRedirect => { StatusCode::TemporaryRedirect => {
debug!("307: Temporary Redirect."); warn!("307: Temporary Redirect.");
return Err(DataError::F301(self)); // FIXME: How is it actually handling the redirect?
return Err(DataError::FeedRedirect(self));
} }
StatusCode::Unauthorized => return Err(self.make_err("401: Unauthorized.", code)), StatusCode::Unauthorized => return Err(self.make_err("401: Unauthorized.", code)),
StatusCode::Forbidden => return Err(self.make_err("403: Forbidden.", code)), StatusCode::Forbidden => return Err(self.make_err("403: Forbidden.", code)),
@ -212,7 +213,7 @@ impl Source {
.then(|res| match res { .then(|res| match res {
Ok(response) => Ok(Loop::Break(response)), Ok(response) => Ok(Loop::Break(response)),
Err(err) => match err { Err(err) => match err {
DataError::F301(s) => { DataError::FeedRedirect(s) => {
info!("Following redirect..."); info!("Following redirect...");
Ok(Loop::Continue(s)) Ok(Loop::Continue(s))
} }