From 0e076e110840abc159dc718c18276eef726436dc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Feb 2021 15:22:35 +0000 Subject: [PATCH] Bug 27680: (follow-up) Attempt to catch the exception Help: I'm struggling to catch the point at which the exception should be thrown to convert it to a 400 error response in the API. '->search' does not actually trigger the DB hit until we reference some data from it.. so we can't use that.. so I tried '->count', but of course.. that drops 'order_by' which is the failure in this case and so we pass through. --- Koha/REST/Plugin/Objects.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index 246aece704..50168d79b1 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -18,6 +18,7 @@ package Koha::REST::Plugin::Objects; use Modern::Perl; use Mojo::Base 'Mojolicious::Plugin'; +use Try::Tiny; use JSON; @@ -114,7 +115,11 @@ sub register { } # Perform search my $objects = $result_set->search( $filtered_params, $attributes ); - my $total = $result_set->search->count; + my $total = try { + $result_set->search->count; + } catch { + warn "Caught in REST Plugin\n"; + }; $c->add_pagination_headers( { -- 2.20.1