From e0f6c4dc6edb4a143dc5e106a750c262ee05c4fc Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Thu, 20 Aug 2015 18:12:42 +1200 Subject: [PATCH] Bug 12478: improve error reporting a bit Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/ElasticSearch.pm | 24 +++++++++++++++++++++++ Koha/SearchEngine/Elasticsearch/Search.pm | 8 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Koha/ElasticSearch.pm b/Koha/ElasticSearch.pm index 4f268d5674..753cc2982b 100644 --- a/Koha/ElasticSearch.pm +++ b/Koha/ElasticSearch.pm @@ -321,6 +321,30 @@ sub _foreach_mapping { } } +=head2 process_error + + die process_error($@); + +This parses an Elasticsearch error message and produces a human-readable +result from it. This result is probably missing all the useful information +that you might want in diagnosing an issue, so the warning is also logged. + +Note that currently the resulting message is not internationalised. This +will happen eventually by some method or other. + +=cut + +sub process_error { + my ($self, $msg) = @_; + + warn $msg; # simple logging + + # This is super-primitive + return "Unable to understand your search query, please rephrase and try again.\n" if $msg =~ /ParseException/; + + return "Unable to perform your search. Please try again.\n"; +} + 1; __END__ diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 1402a79edd..6ee829500a 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -89,7 +89,13 @@ sub search { %$params, trace_calls => 1, ) ) unless $self->store; - my $results = $self->store->bag->search( %$query, %paging ); + my $error; + my $results = eval { + $self->store->bag->search( %$query, %paging ); + }; + if ($@) { + die $self->process_error($@); + } return $results; } -- 2.39.5