From 29d337065a7ffbaf540b5a993a33ee9cbb5503fa Mon Sep 17 00:00:00 2001 From: Arnau Siches Date: Sun, 24 Apr 2016 13:20:09 +0100 Subject: [PATCH] Handle TimeTableResponse status error properly --- src/cmd.rs | 2 +- src/tfl/line.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index cef0542..35d9f00 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -112,7 +112,7 @@ fn transform_gtfs(lines: Vec) { }; let id = route_section_id(&line, &route_section); - println!("\t{}, Has Timetable: {}, Duplicate: {}", id, has_timetable, route_section_ids.contains(&id)); + println!(" {}, Has Timetable: {}, Duplicate: {}", id, has_timetable, route_section_ids.contains(&id)); route_section_ids.insert(id.clone()); route_section_count += 1; } diff --git a/src/tfl/line.rs b/src/tfl/line.rs index d98eafd..dfcadd6 100644 --- a/src/tfl/line.rs +++ b/src/tfl/line.rs @@ -1,4 +1,4 @@ -use ansi_term::Colour::{Green, Blue}; +use ansi_term::Colour::{Green, Blue, Red}; use std::fmt; use std::collections::HashSet; @@ -211,6 +211,8 @@ pub struct TimeTableResponse { pub stations: Vec, pub stops: Vec, pub timetable: RoutesTimeTables, + #[serde(rename="statusErrorMessage")] + pub status_error_message: Option, } #[derive(Clone, Debug, Deserialize)] @@ -221,10 +223,11 @@ pub struct Sequence { impl TimeTableResponse { pub fn first_timetable(&self) -> Option<&TimeTable> { - if self.timetable.routes.is_empty() { - Some(&self.timetable.routes[0]) - } else { + if let Some(ref message) = self.status_error_message { + println!("{} {}", Red.bold().paint("Error:"), message); None + } else { + Some(&self.timetable.routes[0]) } }