Bug 33047: Return 404 instead of 500 when biblio does not exist

If the biblionumber or the itemnumber passed in parameter does not
exist we should return 404 instead of exploding with a 500.

Test plan:
Attach cover images to biblio and items
Notice that the UI is working correctly (staff and OPAC)
Hit catalogue/image.pl and opac/opac-image.pl with non-existent
biblionumber and imagenumber
Notice that you now get 404 instead of 500

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 5f43478512)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit cf31471089)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2023-05-11 15:49:08 +02:00 committed by Matt Blenkinsop
parent e03ea17b97
commit 76baece363
2 changed files with 30 additions and 17 deletions

View file

@ -25,15 +25,14 @@
use Modern::Perl;
use CGI qw ( -utf8 ); #qw(:standard escapeHTML);
use CGI qw ( -utf8 );
use C4::Context;
use Koha::CoverImages;
use Koha::Biblios;
use Koha::Exceptions;
use Koha::CoverImages;
$| = 1;
my $data = CGI->new;
my $input = CGI->new;
my $imagenumber;
=head1 NAME
@ -60,15 +59,22 @@ imagenumber, a random image is selected.
my ( $image );
if ( C4::Context->preference("LocalCoverImages") ) {
my $imagenumber = $data->param('imagenumber');
my $biblionumber = $data->param('biblionumber');
my $imagenumber = $input->param('imagenumber');
my $biblionumber = $input->param('biblionumber');
if ( defined $imagenumber ) {
$imagenumber = $data->param('imagenumber');
$imagenumber = $input->param('imagenumber');
$image = Koha::CoverImages->find($imagenumber);
unless ($image) {
print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
}
elsif ( defined $biblionumber ) {
my $biblio = Koha::Biblios->find($biblionumber);
Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio;
unless ($biblio) {
print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
my $cover_images = $biblio->cover_images;
if ( $cover_images->count ) {
$image = $cover_images->next;
@ -79,11 +85,11 @@ if ( C4::Context->preference("LocalCoverImages") ) {
$image ||= Koha::CoverImages->no_image;
my $image_data =
$data->param('thumbnail')
$input->param('thumbnail')
? $image->thumbnail
: $image->imagefile;
print $data->header(
print $input->header(
-type => $image->mimetype,
-expires => '+30m',
-Content_Length => length($image_data)

View file

@ -32,7 +32,7 @@ use Koha::CoverImages;
$| = 1;
my $data = CGI->new;
my $input = CGI->new;
my $imagenumber;
=head1 NAME
@ -59,15 +59,22 @@ imagenumber, a random image is selected.
my ( $image );
if ( C4::Context->preference("OPACLocalCoverImages") ) {
my $imagenumber = $data->param('imagenumber');
my $biblionumber = $data->param('biblionumber');
my $imagenumber = $input->param('imagenumber');
my $biblionumber = $input->param('biblionumber');
if ( defined $imagenumber ) {
$imagenumber = $data->param('imagenumber');
$imagenumber = $input->param('imagenumber');
$image = Koha::CoverImages->find($imagenumber);
unless ($image) {
print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
}
elsif ( defined $biblionumber ) {
my $biblio = Koha::Biblios->find($biblionumber);
Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio;
unless ($biblio) {
print $input->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
my $cover_images = $biblio->cover_images;
if ( $cover_images->count ) {
$image = $cover_images->next;
@ -78,11 +85,11 @@ if ( C4::Context->preference("OPACLocalCoverImages") ) {
$image ||= Koha::CoverImages->no_image;
my $image_data =
$data->param('thumbnail')
$input->param('thumbnail')
? $image->thumbnail
: $image->imagefile;
print $data->header(
print $input->header(
-type => $image->mimetype,
-expires => '+30m',
-Content_Length => length($image_data)