From 1b43f08155fc7244b7ee231aaee4c20ee35f2066 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 7 Jan 2020 18:29:04 +0100 Subject: handle UserAgent timeouts gracefully --- lib/DBInfoscreen/Controller/Stationboard.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 9f0bd31..797cde9 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -142,10 +142,14 @@ sub get_hafas_trip_id { } $ua->request_timeout(2); - my $res - = $ua->get( - $url => { 'User-Agent' => "dbf.finalrewind.org/${dbf_version}" } ) - ->result; + my $res = eval { + $ua->get( + $url => { 'User-Agent' => "dbf.finalrewind.org/${dbf_version}" } ) + ->result; + }; + if ($@) { + return; + } if ( $res->is_error ) { return; } @@ -182,8 +186,11 @@ sub check_wagonorder { } $ua->request_timeout(2); - my $res = $ua->head($url)->result; + my $res = eval { $ua->head($url)->result }; + if ($@) { + return; + } if ( $res->is_error ) { $cache->set( $url, 'n' ); return; @@ -201,8 +208,11 @@ sub hafas_json_req { return $content; } - my $res = $ua->get($url)->result; + my $res = eval { $ua->get($url)->result }; + if ($@) { + return; + } if ( $res->is_error ) { return; } @@ -228,8 +238,11 @@ sub hafas_xml_req { return $content; } - my $res = $ua->get($url)->result; + my $res = eval { $ua->get($url)->result }; + if ($@) { + return; + } if ( $res->is_error ) { $cache->freeze( $url, {} ); return; -- cgit v1.2.3