summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Helper/HAFAS.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-09-10 21:20:26 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-09-10 21:20:26 +0200
commit874de1129819d4d4559e88d75f8f30b51f66ba90 (patch)
treeda0bfac5bfa237138b64097e3b330b54ade7cba3 /lib/Travelynx/Helper/HAFAS.pm
parenteb93ee40c9117db4947a5ce365aaec1a057fae94 (diff)
handle rejected promises; do not accidentally duplicate rejections
Diffstat (limited to 'lib/Travelynx/Helper/HAFAS.pm')
-rw-r--r--lib/Travelynx/Helper/HAFAS.pm22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Travelynx/Helper/HAFAS.pm b/lib/Travelynx/Helper/HAFAS.pm
index 572f8fa..1fd66b5 100644
--- a/lib/Travelynx/Helper/HAFAS.pm
+++ b/lib/Travelynx/Helper/HAFAS.pm
@@ -34,8 +34,7 @@ sub get_polyline_p {
my $version = $self->{version};
if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- return $promise;
+ return $promise->resolve($content);
}
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
@@ -97,11 +96,13 @@ sub get_polyline_p {
else {
$promise->resolve($ret);
}
+ return;
}
)->catch(
sub {
my ($err) = @_;
$promise->reject($err);
+ return;
}
)->wait;
@@ -144,11 +145,13 @@ sub get_tripid_p {
}
}
$promise->reject;
+ return;
}
)->catch(
sub {
my ($err) = @_;
$promise->reject($err);
+ return;
}
)->wait;
@@ -162,8 +165,7 @@ sub get_rest_p {
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- return $promise;
+ return $promise->resolve($content);
}
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
@@ -180,12 +182,14 @@ sub get_rest_p {
my $json = JSON->new->decode( $tx->res->body );
$cache->freeze( $url, $json );
$promise->resolve($json);
+ return;
}
)->catch(
sub {
my ($err) = @_;
$self->{log}->warn("get($url): $err");
$promise->reject($err);
+ return;
}
)->wait;
return $promise;
@@ -198,8 +202,7 @@ sub get_json_p {
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- return $promise;
+ return $promise->resolve($content);
}
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
@@ -222,12 +225,14 @@ sub get_json_p {
my $json = JSON->new->decode($body);
$cache->freeze( $url, $json );
$promise->resolve($json);
+ return;
}
)->catch(
sub {
my ($err) = @_;
$self->{log}->warn("get($url): $err");
$promise->reject($err);
+ return;
}
)->wait;
return $promise;
@@ -240,8 +245,7 @@ sub get_xml_p {
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- return $promise;
+ return $promise->resolve($content);
}
$self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
@@ -303,12 +307,14 @@ sub get_xml_p {
$cache->freeze( $url, $traininfo );
$promise->resolve($traininfo);
+ return;
}
)->catch(
sub {
my ($err) = @_;
$self->{log}->warn("get($url): $err");
$promise->reject($err);
+ return;
}
)->wait;
return $promise;