From 4e5d250b7304994b98da342717c1c7acbea250d4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 21 Nov 2020 10:44:27 +0100 Subject: Do not croak when receiving invalid XML --- lib/Travel/Status/DE/HAFAS.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 670cba6..839a599 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -180,9 +180,15 @@ sub new { # errors in delay="...") when setting the language to dutch/italian. # No, I don't know why. - $ref->{tree} = XML::LibXML->load_xml( - string => $ref->{raw_xml}, - ); + eval { $ref->{tree} = XML::LibXML->load_xml( string => $ref->{raw_xml} ) }; + + if ( my $err = $@ ) { + if ( $ref->{developer_mode} ) { + say $ref->{raw_xml}; + } + $ref->{errstr} = "Backend returned invalid XML: $err"; + return $ref; + } if ( $ref->{developer_mode} ) { say $ref->{tree}->toString(1); -- cgit v1.2.3