Bug 33053: Handle invalid biblio_id more robustly
This patch addresses the fact the invalid FK error might differ under some circumstances. We could try to catch the exception adding another case, but I think this pattern is cleaner and the authors didn't provide a fix. We can discuss it later, as this controller class has several things to review. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
d236f73fbc
commit
c1fe7406b9
1 changed files with 9 additions and 2 deletions
|
@ -105,9 +105,16 @@ sub add {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
return try {
|
||||
my $item_group_data = $c->validation->param('body');
|
||||
|
||||
my $biblio = Koha::Biblios->find( $c->param('biblio_id') );
|
||||
return $c->render(
|
||||
status => 404,
|
||||
openapi => { error => 'Object not found' }
|
||||
) unless $biblio;
|
||||
|
||||
my $item_group_data = $c->req->json;
|
||||
# biblio_id comes from the path
|
||||
$item_group_data->{biblio_id} = $c->validation->param('biblio_id');
|
||||
$item_group_data->{biblio_id} = $biblio->id;
|
||||
|
||||
my $item_group = Koha::Biblio::ItemGroup->new_from_api($item_group_data);
|
||||
$item_group->store->discard_changes();
|
||||
|
|
Loading…
Reference in a new issue