From 345d4b3865f5ab0cc58e8382b18bf9fa1cbfa630 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 8 Jan 2018 02:41:37 +0200 Subject: [PATCH] Check more http status codes when parsing feeds. --- hammond-data/src/models/queryables.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index d1a9cc0..35b342e 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -630,6 +630,7 @@ impl<'a> Source { // TODO: Refactor into TryInto once it lands on stable. pub fn into_feed(mut self, ignore_etags: bool) -> Result { use reqwest::header::{EntityTag, Headers, HttpDate, IfModifiedSince, IfNoneMatch}; + use reqwest::StatusCode; let mut headers = Headers::new(); @@ -655,12 +656,26 @@ impl<'a> Source { self.update_etag(&req)?; // TODO match on more stuff - // 301: Permanent redirect of the url - // 302: Temporary redirect of the url + // 301: Moved Permanently // 304: Up to date Feed, checked with the Etag + // 307: Temporary redirect of the url + // 308: Permanent redirect of the url + // 401: Unathorized + // 403: Forbidden + // 408: Timeout // 410: Feed deleted match req.status() { - reqwest::StatusCode::NotModified => bail!("304, skipping.."), + StatusCode::NotModified => bail!("304: skipping.."), + StatusCode::TemporaryRedirect => debug!("307: Temporary Redirect."), + // TODO: Change the source uri to the new one + StatusCode::MovedPermanently | StatusCode::PermanentRedirect => { + warn!("Feed was moved permanently.") + } + StatusCode::Unauthorized => bail!("401: Unauthorized."), + StatusCode::Forbidden => bail!("403: Forbidden."), + StatusCode::NotFound => bail!("404: Not found."), + StatusCode::RequestTimeout => bail!("408: Request Timeout."), + StatusCode::Gone => bail!("410: Feed was deleted."), _ => (), };