diff options
author | Daniel Friesel <derf@finalrewind.org> | 2014-06-23 18:24:17 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2014-06-23 18:24:17 +0200 |
commit | f734fa35b4a14b9091632aa305b7fcceed7c4c57 (patch) | |
tree | 7c49a39f2d9e8119a1915076ec74324b03614f8b /lib/Travel/Status | |
parent | 616d793d710df2a18e9ef89dbe1b6e56e1c1c5d5 (diff) |
Do not error out if only partial data is available (closes #4)
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r-- | lib/Travel/Status/DE/IRIS.pm | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index 381b021..89cbb88 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -43,7 +43,8 @@ sub new { my $res_st = $ua->get( $self->{iris_base} . '/station/' . $opt{station} ); if ( $res_st->is_error ) { - $self->{errstr} = $res_st->status_line; + $self->{errstr} = 'Failed to fetch station data: Server returned ' + . $res_st->status_line; return $self; } @@ -159,7 +160,8 @@ sub get_timetable { $dt->strftime( $self->{iris_base} . "/plan/${eva}/%y%m%d/%H" ) ); if ( $res->is_error ) { - $self->{errstr} = $res->status_line; + $self->{warnstr} = 'Failed to fetch a schedule part: Server returned ' + . $res->status_line; return $self; } @@ -184,7 +186,8 @@ sub get_realtime { my $res = $self->{user_agent}->get( $self->{iris_base} . "/fchg/${eva}" ); if ( $res->is_error ) { - $self->{errstr} = $res->status_line; + $self->{warnstr} = 'Failed to fetch realtime data: Server returned ' + . $res->status_line; return $self; } @@ -282,6 +285,12 @@ sub results { return @{ $self->{results} // [] }; } +sub warnstr { + my ($self) = @_; + + return $self->{warnstr}; +} + 1; __END__ @@ -364,7 +373,7 @@ All other options are passed to the LWP::UserAgent(3pm) constructor. =item $status->errstr -In case of an HTTP request or IRIS error, returns a string describing it. +In case of a fatal HTTP request or IRIS error, returns a string describing it. Returns undef otherwise. =item $status->results @@ -372,6 +381,11 @@ Returns undef otherwise. Returns a list of Travel::Status::DE::IRIS(3pm) objects, each one describing one arrival and/or departure. +=item $status->errstr + +In case of a (probably) non-fatal HTTP request or IRIS error, returns a string +describing it. Returns undef otherwise. + =back =head1 DIAGNOSTICS |