Bug 29857: Make the exception classes inherit from the base class
[koha.git] / Koha / Exceptions / Patron / Relationship.pm
1 package Koha::Exceptions::Patron::Relationship;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::Exceptions::Exception;
21
22 use Exception::Class (
23
24     'Koha::Exceptions::Patron::Relationship' => {
25         isa => 'Koha::Exceptions::Exception',
26     },
27     'Koha::Exceptions::Patron::Relationship::DuplicateRelationship' => {
28         isa         => 'Koha::Exceptions::Patron::Relationship',
29         description => 'There can only be one relationship between patrons in a direction',
30         fields      => [ 'guarantor_id', 'guarantee_id' ]
31     },
32     'Koha::Exceptions::Patron::Relationship::InvalidRelationship' => {
33         isa         => 'Koha::Exceptions::Patron::Relationship',
34         description => 'The specified relationship is invalid',
35         fields      =>  ['relationship','no_relationship']
36     }
37 );
38
39 sub full_message {
40     my $self = shift;
41
42     my $msg = $self->message;
43
44     unless ( $msg) {
45         if ( $self->isa('Koha::Exceptions::Patron::Relationship::InvalidRelationship') ) {
46             if ( $self->no_relationship ) {
47                 $msg = sprintf( "No relationship passed." );
48             }
49             else {
50                 $msg = sprintf("Invalid relationship passed, '%s' is not defined.", $self->relationship );
51             }
52         }
53         elsif ( $self->isa('Koha::Exceptions::Patron::Relationship::DuplicateRelationship') ) {
54             $msg
55                 = sprintf(
56                 "There already exists a relationship for the same guarantor (%s) and guarantee (%s) combination",
57                 $self->guarantor_id, $self->guarantee_id );
58         }
59     }
60
61     return $msg;
62 }
63
64 =head1 NAME
65
66 Koha::Exceptions::Patron::Relationship - Base class for patron relatioship exceptions
67
68 =head1 Exceptions
69
70 =head2 Koha::Exceptions::Patron::Relationship
71
72 Generic Patron exception
73
74 =head2 Koha::Exceptions::Patron::Relationship::DuplicateRelationship
75
76 Exception to be used when more than one relationship is requested for a
77 pair of patrons in the same direction.
78
79 =head2 Koha::Exceptions::Patron::Relationship::InvalidRelationship
80
81 Exception to be used when an invalid relationship is passed.
82
83 =head1 Class methods
84
85 =head2 full_message
86
87 Overloaded method for exception stringifying.
88
89 =cut
90
91 1;