diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-11-21 10:44:27 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-11-21 10:48:33 +0100 |
commit | 4e5d250b7304994b98da342717c1c7acbea250d4 (patch) | |
tree | 1609d59fe19f0ffdbdfbeb29f9cbeb77ebd53747 /lib/Travel/Status | |
parent | 220b3bf395fa4aa87a0b5b9c161ac6e59ba08d58 (diff) |
Do not croak when receiving invalid XML
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 12 |
1 files changed, 9 insertions, 3 deletions
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); |