From 93f8d4c7c89b03fc29d60159279408adbdcbde56 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 4 Jan 2021 11:24:51 -0300 Subject: [PATCH] Bug 27330: Return 403 if club has no enrollments This patch makes the controller script return a 403 as it should [1] instead of a plain 500. To test: 1. Apply the regressions tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/clubs_holds.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D [1] https://www.restapitutorial.com/httpstatuscodes.html Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit ea0696831fadd4b633c90fc7ccd29144e9a6b87a) Signed-off-by: Fridolin Somers (cherry picked from commit 4f3d15c8d2e470e7e1f1175879a95d0b9e53a5c7) Signed-off-by: Andrew Fuerste-Henry --- Koha/REST/V1/Clubs/Holds.pm | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Koha/REST/V1/Clubs/Holds.pm b/Koha/REST/V1/Clubs/Holds.pm index 78f741acd0..9a4aaa052a 100644 --- a/Koha/REST/V1/Clubs/Holds.pm +++ b/Koha/REST/V1/Clubs/Holds.pm @@ -128,19 +128,9 @@ sub add { } catch { if ( blessed $_ ) { - if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { - my $broken_fk = $_->broken_fk; - - if ( grep { $_ eq $broken_fk } keys %{$Koha::REST::V1::Clubs::Holds::to_api_mapping} ) { - $c->render( - status => 404, - openapi => $Koha::REST::V1::Clubs::Holds::to_api_mapping->{$broken_fk} . ' not found.' - ); - } - } - elsif ($_->isa('Koha::Exceptions::ClubHold')) { + if ($_->isa('Koha::Exceptions::ClubHold::NoPatrons')) { return $c->render( - status => 500, + status => 403, openapi => { error => $_->description } ); } -- 2.39.5