summaryrefslogtreecommitdiff
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
parenteb93ee40c9117db4947a5ce365aaec1a057fae94 (diff)
handle rejected promises; do not accidentally duplicate rejections
-rwxr-xr-xlib/Travelynx.pm27
-rw-r--r--lib/Travelynx/Helper/DBDB.pm22
-rw-r--r--lib/Travelynx/Helper/HAFAS.pm22
3 files changed, 54 insertions, 17 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 9d1084c..f621139 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1260,6 +1260,13 @@ sub startup {
{ user_id => $uid }
);
}
+ return;
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->app->log->warn("add_route_timestamps: $err");
+ return;
}
)->wait;
}
@@ -1394,6 +1401,11 @@ sub startup {
{ user_id => $uid }
);
}
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->app->log->warn("add_route_timestamps: $err");
+ }
)->wait;
if ( $train->sched_departure ) {
@@ -1476,6 +1488,11 @@ sub startup {
);
}
}
+ )->catch(
+ sub {
+ # no wagonorder? no problem.
+ return;
+ }
)->wait;
}
@@ -1497,6 +1514,11 @@ sub startup {
{ user_id => $uid }
);
}
+ )->catch(
+ sub {
+ # no stationinfo? no problem.
+ return;
+ }
)->wait;
}
@@ -1518,6 +1540,11 @@ sub startup {
{ user_id => $uid }
);
}
+ )->catch(
+ sub {
+ # no stationinfo? no problem.
+ return;
+ }
)->wait;
}
}
diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm
index 2161962..3f181f6 100644
--- a/lib/Travelynx/Helper/DBDB.pm
+++ b/lib/Travelynx/Helper/DBDB.pm
@@ -32,12 +32,10 @@ sub has_wagonorder_p {
if ( my $content = $cache->get($url) ) {
if ( $content eq 'y' ) {
- $promise->resolve;
- return $promise;
+ return $promise->resolve;
}
elsif ( $content eq 'n' ) {
- $promise->reject;
- return $promise;
+ return $promise->reject;
}
}
@@ -53,11 +51,13 @@ sub has_wagonorder_p {
$cache->set( $url, 'n' );
$promise->reject;
}
+ return;
}
)->catch(
sub {
$cache->set( $url, 'n' );
$promise->reject;
+ return;
}
)->wait;
return $promise;
@@ -86,11 +86,13 @@ sub get_wagonorder_p {
my $json = JSON->new->decode($body);
$cache->freeze( $url, $json );
$promise->resolve($json);
+ return;
}
)->catch(
sub {
my ($err) = @_;
$promise->reject($err);
+ return;
}
)->wait;
return $promise;
@@ -105,8 +107,7 @@ sub get_stationinfo_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} )
@@ -115,17 +116,20 @@ sub get_stationinfo_p {
my ($tx) = @_;
if ( my $err = $tx->error ) {
- return $promise->reject("HTTP $err->{code} $err->{message}");
+ $promise->reject("HTTP $err->{code} $err->{message}");
+ return;
}
my $json = $tx->result->json;
$cache->freeze( $url, $json );
- return $promise->resolve($json);
+ $promise->resolve($json);
+ return;
}
)->catch(
sub {
my ($err) = @_;
- return $promise->reject($err);
+ $promise->reject($err);
+ return;
}
)->wait;
return $promise;
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;