Bug 36891: Restore returning 404 from svc/bib when the bib number doesn't exist

Changing from GetMarcBiblio to Biblios->find plus metadata->record lost the
way that svc/bib used to return 404 when the bib number wasn't found. This
patch restores that by checking for undef after the Biblios->find step.

Test plan:
1. Load e.g. http://127.0.0.1:8081/cgi-bin/koha/svc/bib/289 which returns an
   XML bib record
2. Load http://127.0.0.1:8081/cgi-bin/koha/svc/bib/99999999 and get a 500 error
2. Appply patch, restart_all
4. Reload http://127.0.0.1:8081/cgi-bin/koha/svc/bib/289 and get the bib again
5. Reload http://127.0.0.1:8081/cgi-bin/koha/svc/bib/99999999 and get a 404

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Phil Ringnalda 2024-05-16 17:01:54 -07:00 committed by Katrin Fischer
parent 1004d47d00
commit 3d1b38b0ad
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

16
svc/bib
View file

@ -70,14 +70,14 @@ sub fetch_bib {
my $record;
my $exception;
my $invalid_metadata = 0;
eval { $record = $biblio->metadata->record( { embed_items => scalar $query->param('items') } ) };
if ($@) {
$exception = $@;
$exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
$record = $biblio->metadata->record_strip_nonxml( { embed_items => scalar $query->param('items') } );
$invalid_metadata = 1;
}
if ( defined $record ) {
if ( defined $biblio ) {
eval { $record = $biblio->metadata->record( { embed_items => scalar $query->param('items') } ) };
if ($@) {
$exception = $@;
$exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
$record = $biblio->metadata->record_strip_nonxml( { embed_items => scalar $query->param('items') } );
$invalid_metadata = 1;
}
print $query->header( -type => 'text/xml', -charset => 'utf-8', -invalid_metadata => $invalid_metadata );
print $record->as_xml_record();
} else {