Bugzilla – Attachment 168879 Details for
Bug 36641
Add an endpoint to list circulation rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36641: (follow-up) Wrap in a try/catch block
Bug-36641-follow-up-Wrap-in-a-trycatch-block.patch (text/plain), 5.38 KB, created by
Martin Renvoize (ashimema)
on 2024-07-12 10:27:30 UTC
(
hide
)
Description:
Bug 36641: (follow-up) Wrap in a try/catch block
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-12 10:27:30 UTC
Size:
5.38 KB
patch
obsolete
>From 81a53b3b1892d75a6ec5c68b20ccbdedda5320f8 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >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 <kyle@bywatersolutions.com> >--- > 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 45d3038ca3a..30e045f0370 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 178855d2107..3f9647943da 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.45.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36641
:
165086
|
167937
|
167938
|
167946
|
167947
|
168018
|
168019
|
168020
|
168023
|
168024
|
168025
|
168365
|
168366
|
168367
|
168368
|
168369
|
168370
|
168378
|
168379
|
168395
|
168396
|
168397
|
168398
|
168399
|
168400
|
168401
|
168841
|
168874
|
168875
|
168876
|
168877
|
168878
|
168879
|
168880
|
168881
|
168882
|
168883
|
168884
|
168905
|
168906
|
168907
|
168908
|
168909
|
168910
|
168911
|
168912
|
168913
|
168914
|
168915
|
168916
|
168926
|
168927
|
168928
|
168929
|
168930
|
168931
|
168932
|
168933
|
168934
|
168935
|
168936
|
168937
|
168938
|
168940
|
169013
|
169014
|
169015
|
169016
|
169017
|
169018
|
169019
|
169020
|
169021
|
169022
|
169023
|
169024
|
169025
|
169026