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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2021-01-04 11:24:51 -03:00 committed by Jonathan Druart
parent 2af262e1f2
commit ea0696831f

View file

@ -128,19 +128,9 @@ sub add {
} }
catch { catch {
if ( blessed $_ ) { if ( blessed $_ ) {
if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { if ($_->isa('Koha::Exceptions::ClubHold::NoPatrons')) {
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')) {
return $c->render( return $c->render(
status => 500, status => 403,
openapi => { error => $_->description } openapi => { error => $_->description }
); );
} }