From a13eaa989f5d93b9b7816a9c819821d79f7eb54f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 8 Sep 2018 11:49:44 +0200 Subject: Catch LibXML parser errors --- lib/Travel/Status/DE/IRIS.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index f9a05ee..efb080d 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -31,7 +31,7 @@ sub new { developer_mode => $opt{developer_mode}, iris_base => $opt{iris_base} // 'http://iris.noncd.db.de/iris-tts/timetable', - lookahead => $opt{lookahead} // ( 2 * 60 ), + lookahead => $opt{lookahead} // ( 2 * 60 ), lookbehind => $opt{lookbehind} // ( 0 * 60 ), main_cache => $opt{main_cache}, rt_cache => $opt{realtime_cache}, @@ -131,7 +131,7 @@ sub new { } @{ $self->{results} } = grep { - my $d = ( $_->departure // $_->arrival ); + my $d = ( $_->departure // $_->arrival ); my $sd = $_->sched_departure // $_->sched_arrival // $d; $d = $d->subtract_datetime( $self->{datetime} ); $sd = $sd->subtract_datetime( $self->{datetime} ); @@ -215,7 +215,12 @@ sub get_station { } } - my $xml_st = XML::LibXML->load_xml( string => $raw ); + my $xml_st; + eval { $xml_st = XML::LibXML->load_xml( string => $raw ) }; + if ($@) { + $self->{errstr} = "Parse error: $@"; + return; + } my $station_node = ( $xml_st->findnodes('//station') )[0]; -- cgit v1.2.3