diff --git a/assets/badges/unknown.svg b/assets/badges/unknown.svg new file mode 100644 index 0000000..959f89d --- /dev/null +++ b/assets/badges/unknown.svg @@ -0,0 +1 @@ +dependenciesdependenciesunknownunknown \ No newline at end of file diff --git a/src/server/assets.rs b/src/server/assets.rs index d92e5be..8eecfe6 100644 --- a/src/server/assets.rs +++ b/src/server/assets.rs @@ -4,6 +4,8 @@ pub static BADGE_UPTODATE_SVG: &'static [u8; 978] = include_bytes!("../../assets/badges/up-to-date.svg"); pub static BADGE_OUTDATED_SVG: &'static [u8; 974] = include_bytes!("../../assets/badges/outdated.svg"); +pub static BADGE_UNKNOWN_SVG: &'static [u8; 972] = + include_bytes!("../../assets/badges/unknown.svg"); pub static STATIC_STYLE_CSS: &'static str = include_str!(concat!(env!("OUT_DIR"), "/style.css")); diff --git a/src/server/mod.rs b/src/server/mod.rs index 50a91fd..c94073f 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -13,7 +13,7 @@ mod views; use ::engine::{Engine, AnalyzeDependenciesOutcome}; use ::models::repo::RepoPath; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] enum StatusFormat { Html, Json, @@ -101,10 +101,14 @@ impl Server { future::Either::B(server.engine.analyze_dependencies(repo_path.clone()).then(move |analyze_result| { match analyze_result { Err(err) => { - let mut response = Response::new(); - response.set_status(StatusCode::InternalServerError); - response.set_body(format!("{:?}", err)); - future::Either::A(future::ok(response)) + if format != StatusFormat::Svg { + let mut response = Response::new(); + response.set_status(StatusCode::BadRequest); + response.set_body(format!("{:?}", err)); + future::Either::A(future::ok(response)) + } else { + future::Either::A(future::ok(views::status_svg(None))) + } }, Ok(analysis_outcome) => { let response = Server::status_format_analysis(analysis_outcome, format, repo_path); @@ -122,7 +126,7 @@ impl Server { StatusFormat::Json => views::status_json(analysis_outcome), StatusFormat::Svg => - views::status_svg(analysis_outcome), + views::status_svg(Some(analysis_outcome)), StatusFormat::Html => views::html::status::render(analysis_outcome, repo_path) } diff --git a/src/server/views/status_svg.rs b/src/server/views/status_svg.rs index e25fc93..1e23d99 100644 --- a/src/server/views/status_svg.rs +++ b/src/server/views/status_svg.rs @@ -4,13 +4,17 @@ use hyper::header::ContentType; use ::server::assets; use ::engine::AnalyzeDependenciesOutcome; -pub fn status_svg(analysis_outcome: AnalyzeDependenciesOutcome) -> Response { +pub fn status_svg(analysis_outcome: Option) -> Response { let mut response = Response::new() .with_header(ContentType("image/svg+xml;charset=utf-8".parse().unwrap())); - if analysis_outcome.deps.any_outdated() { - response.set_body(assets::BADGE_OUTDATED_SVG.to_vec()); + if let Some(outcome) = analysis_outcome { + if outcome.deps.any_outdated() { + response.set_body(assets::BADGE_OUTDATED_SVG.to_vec()); + } else { + response.set_body(assets::BADGE_UPTODATE_SVG.to_vec()); + } } else { - response.set_body(assets::BADGE_UPTODATE_SVG.to_vec()); + response.set_body(assets::BADGE_UNKNOWN_SVG.to_vec()); } response }