From 1a2dd42aafb2138bd54d1f1a196fb5ad01cc4f97 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 8 Jul 2020 11:01:48 +0000 Subject: [PATCH] Bug 25952: Add error-handling to prevent errors from rate limiting This patch makes sure there is a successful response before trying to decode the response. If you search for "koha-plugin" in the Bywater and Theke repos, you'll quickly exceed your API rate limit, and you'll stop getting successful responses. To test: 0) Don't apply patch yet 1) Enable plugins 2) Enable plugin_repos 3) Search for koha-plugin a few times 4) Notice how Plack crashes with a visible error in the browser 5) Apply the patch 6) restart_all (in koha-testing-docker) 7) Search for koha-plugin 8) Observe that no search results are returned and there are no errors in the browser --- plugins/plugins-home.pl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl index e3335ab4bd..3736367da4 100755 --- a/plugins/plugins-home.pl +++ b/plugins/plugins-home.pl @@ -71,14 +71,18 @@ if ($plugins_enabled) { foreach my $result ( @{ $response->{items} } ) { next unless $result->{name} =~ /^koha-plugin-/; my $releases = $result->{url} . "/releases/latest"; - my $release = from_json( get($releases) ); - for my $asset ( @{$release->{assets}} ) { - if ($asset->{browser_download_url} =~ m/\.kpz$/) { - $result->{install_name} = $asset->{name}; - $result->{install_url} = $asset->{browser_download_url}; + my $releases_response = get($releases); + if ($releases_response){ + my $release = from_json( $releases_response ); + for my $asset ( @{$release->{assets}} ) { + if ($asset->{browser_download_url} =~ m/\.kpz$/) { + $result->{install_name} = $asset->{name}; + $result->{install_url} = $asset->{browser_download_url}; + } } + push( @results, { repo => $r, result => $result } ); } - push( @results, { repo => $r, result => $result } ); + #FIXME: tell the user that the response failed } } } -- 2.11.0