From b87c8728803cd642b24b215525d9cb196eaf4c27 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Thu, 16 May 2024 17:01:54 -0700 Subject: [PATCH] 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 Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer (cherry picked from commit 3d1b38b0ade54dae8d565e2195e2e97f4826a0b6) Signed-off-by: Lucas Gass (cherry picked from commit d3383fed5cb0e23dbcf4bab5422940ab8b0770a7) Signed-off-by: Fridolin Somers --- svc/bib | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/svc/bib b/svc/bib index 53e6fc753e..da96e01f9a 100755 --- a/svc/bib +++ b/svc/bib @@ -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 { -- 2.39.5