diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d6a46fb185..23841897bc 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1706,7 +1706,12 @@ sub to_api { $args = defined $args ? {%$args} : {}; delete $args->{embed}; - my $json_biblioitem = $self->biblioitem->to_api( $args ); + my $biblioitem = $self->biblioitem; + + Koha::Exceptions::RelatedObjectNotFound->throw( accessor => 'biblioitem', class => 'Koha::Biblioitem' ) + unless $biblioitem; + + my $json_biblioitem = $biblioitem->to_api($args); return unless $json_biblioitem; return { %$json_biblioitem, %$json_biblio }; diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm index 0d5a1ac1ed..d308f19229 100644 --- a/Koha/Exceptions.pm +++ b/Koha/Exceptions.pm @@ -7,16 +7,16 @@ use Koha::Exception; use Exception::Class ( 'Koha::Exceptions::BadParameter' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'A bad parameter was given', - fields => ['parameter'], + fields => ['parameter'], }, 'Koha::Exceptions::DuplicateObject' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'Same object already exists', }, 'Koha::Exceptions::FileNotFound' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'File not found', fields => ['filename'], }, @@ -26,57 +26,62 @@ use Exception::Class ( fields => ['invalid_status'], }, 'Koha::Exceptions::ObjectNotFound' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'The required object doesn\'t exist', }, 'Koha::Exceptions::PayloadTooLarge' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'Request entity is larger than limits defined by server', }, 'Koha::Exceptions::ObjectNotCreated' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'The object have not been created', }, + 'Koha::Exceptions::RelatedObjectNotFound' => { + isa => 'Koha::Exception', + description => 'The requested related object does not exist', + fields => [ 'accessor', 'class' ], + }, 'Koha::Exceptions::CannotDeleteDefault' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'The default value cannot be deleted' }, 'Koha::Exceptions::CannotDeleteSystem' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'The system value cannot be deleted' }, 'Koha::Exceptions::MissingParameter' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'A required parameter is missing', - fields => ['parameter'], + fields => ['parameter'], }, 'Koha::Exceptions::TooManyParameters' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'Too many parameters given', }, 'Koha::Exceptions::ParameterTooHigh' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'A passed parameter value is too high' }, 'Koha::Exceptions::NoChanges' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'No changes were made', }, 'Koha::Exceptions::WrongParameter' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'Parameter has wrong value or type', - fields => ['name', 'value', 'type'], + fields => [ 'name', 'value', 'type' ], }, 'Koha::Exceptions::NoPermission' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'You do not have permission for this action', }, 'Koha::Exceptions::CannotAddLibraryLimit' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'General problem adding a library limit' }, 'Koha::Exceptions::UnderMaintenance' => { - isa => 'Koha::Exception', + isa => 'Koha::Exception', description => 'Koha is under maintenance.' }, 'Koha::Exceptions::NoInteger' => {