From 879b3b38150960786341489a44609ac300725413 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 12 Dec 2021 17:24:24 +0100 Subject: fix caching fuckup introduced in 2e5a1b0a79e3a54e159cf598b2a0d398109a7bf4 --- lib/Travelynx/Helper/DBDB.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm index fbee1b9..f78f9ec 100644 --- a/lib/Travelynx/Helper/DBDB.pm +++ b/lib/Travelynx/Helper/DBDB.pm @@ -34,7 +34,7 @@ sub has_wagonorder_p { my $cache = $self->{cache}; my $promise = Mojo::Promise->new; - if ( my $content = $cache->get($url) ) { + if ( my $content = $cache->get("HEAD $url") ) { if ( $content eq 'n' ) { return $promise->reject; } @@ -48,18 +48,18 @@ sub has_wagonorder_p { sub { my ($tx) = @_; if ( $tx->result->is_success ) { - $cache->set( $url, 'a' ); + $cache->set( "HEAD $url", 'a' ); $promise->resolve('a'); } else { - $cache->set( $url, 'n' ); + $cache->set( "HEAD $url", 'n' ); $promise->reject; } return; } )->catch( sub { - $cache->set( $url, 'n' ); + $cache->set( "HEAD $url", 'n' ); $promise->reject; return; } @@ -90,11 +90,17 @@ sub get_wagonorder_p { ->then( sub { my ($tx) = @_; - my $body = decode( 'utf-8', $tx->res->body ); - my $json = JSON->new->decode($body); - $cache->freeze( $url, $json ); - $promise->resolve($json); + if ( $tx->result->is_success ) { + my $body = decode( 'utf-8', $tx->res->body ); + my $json = JSON->new->decode($body); + $cache->freeze( $url, $json ); + $promise->resolve($json); + } + else { + my $code = $tx->code; + $promise->reject("HTTP ${code}"); + } return; } )->catch( -- cgit v1.2.3