Bug 12478: improve error reporting a bit
authorRobin Sheat <robin@catalyst.net.nz>
Thu, 20 Aug 2015 06:12:42 +0000 (18:12 +1200)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 26 Apr 2016 20:20:07 +0000 (20:20 +0000)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Koha/ElasticSearch.pm
Koha/SearchEngine/Elasticsearch/Search.pm

index 4f268d5..753cc29 100644 (file)
@@ -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__
index 1402a79..6ee8295 100644 (file)
@@ -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;
 }