Bug 25952: Skip invalid repositories when searching for plugins
This patch prevents the end-user to get the ugly 500 "malformed JSON string" when something wrong happens with the plugin search. It happens currently in ktd with the plugin repos listed in $KOHA_CONF An error is reported to the UI Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
d51dc1fc69
commit
438e51351d
|
|
@ -85,6 +85,15 @@
|
|||
</div>
|
||||
[% END %]
|
||||
|
||||
[% IF search_errors %]
|
||||
<h2>Search errors</h2>
|
||||
<div class="page-section">
|
||||
[% FOREACH error IN search_errors %]
|
||||
<div class="alert alert-warning">Cannot search repository [% error.repo.name | html %]: [% error.error | html %]</div>
|
||||
[% END %]
|
||||
</div>
|
||||
[% END %]
|
||||
|
||||
[% IF search_results %]
|
||||
<h2>Search results</h2>
|
||||
<div class="page-section">
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use CGI qw ( -utf8 );
|
|||
|
||||
use JSON qw( from_json );
|
||||
use LWP::Simple qw( get );
|
||||
use Try::Tiny;
|
||||
|
||||
use Koha::Plugins;
|
||||
use C4::Auth qw( get_template_and_user );
|
||||
|
|
@ -63,7 +64,7 @@ if ($plugins_enabled) {
|
|||
$template->param( plugins_restricted => C4::Context->config('plugins_restricted') );
|
||||
|
||||
$template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
|
||||
my @results;
|
||||
my ( @results, @errors );
|
||||
if ($plugin_search) {
|
||||
my $repos = C4::Context->config('plugin_repos');
|
||||
|
||||
|
|
@ -73,6 +74,7 @@ if ($plugins_enabled) {
|
|||
}
|
||||
|
||||
foreach my $r ( @{ $repos->{repo} } ) {
|
||||
try {
|
||||
if ( $r->{service} eq 'github' ) {
|
||||
my $url =
|
||||
"https://api.github.com/search/repositories?q=$plugin_search+user:$r->{org_name}+in:name,description";
|
||||
|
|
@ -131,10 +133,15 @@ if ($plugins_enabled) {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
warn $_;
|
||||
push @errors, { repo => $r, error => $_ };
|
||||
};
|
||||
}
|
||||
|
||||
$template->param(
|
||||
search_results => \@results,
|
||||
search_errors => \@errors,
|
||||
search_term => $plugin_search,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue