Bug 14570: Add error handling to Koha::Patron::Relationship->store
[koha.git] / Koha / Exceptions / Patron / Relationship.pm
blobd8a79d0810ba18bde0efa219e934e68bcfd09f82
1 package Koha::Exceptions::Patron::Relationship;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use Modern::Perl;
20 use Exception::Class (
22 'Koha::Exceptions::Patron::Relationship' => {
23 description => 'Something went wrong!',
25 'Koha::Exceptions::Patron::Relationship::DuplicateRelationship' => {
26 isa => 'Koha::Exceptions::Patron::Relationship',
27 description => 'There can only be one relationship between patrons in a direction',
28 fields => [ 'guarantor_id', 'guarantee_id' ]
30 'Koha::Exceptions::Patron::Relationship::InvalidRelationship' => {
31 isa => 'Koha::Exceptions::Patron::Relationship',
32 description => 'The specified relationship is invalid',
33 fields => ['relationship','no_relationship']
37 sub full_message {
38 my $self = shift;
40 my $msg = $self->message;
42 unless ( $msg) {
43 if ( $self->isa('Koha::Exceptions::Patron::Relationship::InvalidRelationship') ) {
44 if ( $self->no_relationship ) {
45 $msg = sprintf( "No relationship passed." );
47 else {
48 $msg = sprintf("Invalid relationship passed, '%s' is not defined.", $self->relationship );
51 elsif ( $self->isa('Koha::Exceptions::Patron::Relationship::DuplicateRelationship') ) {
52 $msg
53 = sprintf(
54 "There already exists a relationship for the same guarantor (%s) and guarantee (%s) combination",
55 $self->guarantor_id, $self->guarantee_id );
59 return $msg;
62 =head1 NAME
64 Koha::Exceptions::Patron::Relationship - Base class for patron relatioship exceptions
66 =head1 Exceptions
68 =head2 Koha::Exceptions::Patron::Relationship
70 Generic Patron exception
72 =head2 Koha::Exceptions::Patron::Relationship::DuplicateRelationship
74 Exception to be used when more than one relationship is requested for a
75 pair of patrons in the same direction.
77 =head2 Koha::Exceptions::Patron::Relationship::InvalidRelationship
79 Exception to be used when an invalid relationship is passed.
81 =head1 Class methods
83 =head2 full_message
85 Overloaded method for exception stringifying.
87 =cut