From 1fa16a527e75d27c3bd7d990068efc697f017b51 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 2 Jul 2024 16:19:19 +0100 Subject: [PATCH] Bug 36641: (follow-up) Wrap in a try/catch block This patch adds the missing try/catch and unhandled exception error handler to the new list_effective_rules endpoint. Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer --- Koha/REST/V1/CirculationRules.pm | 104 ++++++++++---------- api/v1/swagger/paths/circulation_rules.yaml | 4 + 2 files changed, 58 insertions(+), 50 deletions(-) diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm index 45d3038ca3..30e045f037 100644 --- a/Koha/REST/V1/CirculationRules.pm +++ b/Koha/REST/V1/CirculationRules.pm @@ -49,63 +49,67 @@ List all effective rules for the requested patron/item/branch combination sub list_effective_rules { my $c = shift->openapi->valid_input or return; - my $item_type = $c->param('item_type_id'); - my $branchcode = $c->param('library_id'); - my $patron_category = $c->param('patron_category_id'); - my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; - - if ($item_type) { - my $type = Koha::ItemTypes->find($item_type); - return $c->render_invalid_parameter_value( - { - path => '/query/item_type_id', - values => { - uri => '/api/v1/item_types', - field => 'item_type_id' + return try { + my $item_type = $c->param('item_type_id'); + my $branchcode = $c->param('library_id'); + my $patron_category = $c->param('patron_category_id'); + my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; + + if ($item_type) { + my $type = Koha::ItemTypes->find($item_type); + return $c->render_invalid_parameter_value( + { + path => '/query/item_type_id', + values => { + uri => '/api/v1/item_types', + field => 'item_type_id' + } } - } - ) unless $type; - } + ) unless $type; + } - if ($branchcode) { - my $library = Koha::Libraries->find($branchcode); - return $c->render_invalid_parameter_value( - { - path => '/query/library_id', - values => { - uri => '/api/v1/libraries', - field => 'library_id' + if ($branchcode) { + my $library = Koha::Libraries->find($branchcode); + return $c->render_invalid_parameter_value( + { + path => '/query/library_id', + values => { + uri => '/api/v1/libraries', + field => 'library_id' + } } - } - ) unless $library; - } + ) unless $library; + } - if ($patron_category) { - my $category = Koha::Patron::Categories->find($patron_category); - return $c->render_invalid_parameter_value( - { - path => '/query/patron_category_id', - values => { - uri => '/api/v1/patron_categories', - field => 'patron_category_id' + if ($patron_category) { + my $category = Koha::Patron::Categories->find($patron_category); + return $c->render_invalid_parameter_value( + { + path => '/query/patron_category_id', + values => { + uri => '/api/v1/patron_categories', + field => 'patron_category_id' + } } - } - ) unless $category; - } - - my $effective_rules = Koha::CirculationRules->get_effective_rules( - { - categorycode => $patron_category, - itemtype => $item_type, - branchcode => $branchcode, - rules => $rules + ) unless $category; } - ); - return $c->render( - status => 200, - openapi => $effective_rules ? $effective_rules : {} - ); + my $effective_rules = Koha::CirculationRules->get_effective_rules( + { + categorycode => $patron_category, + itemtype => $item_type, + branchcode => $branchcode, + rules => $rules + } + ); + + return $c->render( + status => 200, + openapi => $effective_rules ? $effective_rules : {} + ); + } catch { + $c->unhandled_exception($_); + }; } 1; diff --git a/api/v1/swagger/paths/circulation_rules.yaml b/api/v1/swagger/paths/circulation_rules.yaml index 178855d210..3f9647943d 100644 --- a/api/v1/swagger/paths/circulation_rules.yaml +++ b/api/v1/swagger/paths/circulation_rules.yaml @@ -43,6 +43,10 @@ description: Bad request schema: $ref: "../swagger.yaml#/definitions/error" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" "403": description: Access forbidden schema: -- 2.39.5