diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-09-10 21:20:26 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-09-10 21:20:26 +0200 |
commit | 874de1129819d4d4559e88d75f8f30b51f66ba90 (patch) | |
tree | da0bfac5bfa237138b64097e3b330b54ade7cba3 /lib/Travelynx/Helper/DBDB.pm | |
parent | eb93ee40c9117db4947a5ce365aaec1a057fae94 (diff) |
handle rejected promises; do not accidentally duplicate rejections
Diffstat (limited to 'lib/Travelynx/Helper/DBDB.pm')
-rw-r--r-- | lib/Travelynx/Helper/DBDB.pm | 22 |
1 files changed, 13 insertions, 9 deletions
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; |