From 98da178eb233eefa90cbbb50ca687ae697597f2d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Feb 2021 15:22:35 +0000 Subject: [PATCH] Bug 27806: (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/Exceptions.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Koha/REST/Plugin/Exceptions.pm b/Koha/REST/Plugin/Exceptions.pm index e9be043aa2..e56f2b28ea 100644 --- a/Koha/REST/Plugin/Exceptions.pm +++ b/Koha/REST/Plugin/Exceptions.pm @@ -54,16 +54,21 @@ sub register { $app->helper( 'unhandled_exception' => sub { my ( $c, $exception ) = @_; + warn "Inside unhandled_exception\n"; - my $req = $c->req; - my $method = $req->method; - my $path = $req->url->to_abs->path; my $type = ""; - if ( blessed $exception ) { - $type = "(" . ref($exception) . ")"; + if ( $exception->isa('Koha::Exceptions::Object::PropertyNotFound') ) { + $c->render( status => 400, json => $_->error ); + } else { + $type = "(" . ref($exception) . ")"; + } } + my $req = $c->req; + my $method = $req->method; + my $path = $req->url->to_abs->path; + my $exception_string = "$exception"; chomp($exception_string); -- 2.20.1