From c94a2b89baca6d52611489c053dce4cf1f170159 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Thu, 16 May 2024 17:01:54 -0700 Subject: [PATCH] Bug 36891: Naive attempt to fix svc/bib to return 404 when bib number not found But of course it can't be simple. After just adding if ( defined $biblio ) and reindenting and tidying what I indented, I'm told that I made two more untidy lines. And there's a bad smell around the "if ( defined $record )" since I don't see how it could be false, because $biblio->metadata->record doesn't return undef. But maybe I'm missing something. --- svc/bib | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/svc/bib b/svc/bib index 53e6fc753e..3e786f2191 100755 --- a/svc/bib +++ b/svc/bib @@ -70,16 +70,18 @@ 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 ) { - print $query->header( -type => 'text/xml', -charset => 'utf-8', -invalid_metadata => $invalid_metadata ); - print $record->as_xml_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; + } + if ( defined $record ) { + print $query->header( -type => 'text/xml', -charset => 'utf-8', -invalid_metadata => $invalid_metadata ); + print $record->as_xml_record(); + } } else { print $query->header( -type => 'text/xml', -status => '404 Not Found' ); } -- 2.44.0