Bug 20434: Update UNIMARC framework - defaults
[koha.git] / Koha / Exceptions / Object.pm
1 package Koha::Exceptions::Object;
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
13 #
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.
17
18 use Modern::Perl;
19
20 use Koha::Exceptions::Exception;
21
22 use Exception::Class (
23     'Koha::Exceptions::Object' => {
24         isa         => 'Koha::Exceptions::Exception',
25     },
26     'Koha::Exceptions::Object::DuplicateID' => {
27         isa         => 'Koha::Exceptions::Object',
28         description => "Duplicate ID passed",
29         fields      =>  ['duplicate_id']
30     },
31     'Koha::Exceptions::Object::FKConstraint' => {
32         isa         => 'Koha::Exceptions::Object',
33         description => "Foreign key constraint broken",
34         fields      =>  ['broken_fk', 'value'],
35     },
36     'Koha::Exceptions::Object::MethodNotFound' => {
37         isa => 'Koha::Exceptions::Object',
38         description => "Invalid method",
39     },
40     'Koha::Exceptions::Object::PropertyNotFound' => {
41         isa => 'Koha::Exceptions::Object',
42         description => "Invalid property",
43     },
44     'Koha::Exceptions::Object::ReadOnlyProperty' => {
45         isa => 'Koha::Exceptions::Object',
46         description => "Change of readonly property attempted",
47         fields => [ 'property' ],
48     },
49     'Koha::Exceptions::Object::MethodNotCoveredByTests' => {
50         isa => 'Koha::Exceptions::Object',
51         description => "Method not covered by tests",
52     },
53     'Koha::Exceptions::Object::BadValue' => {
54         isa         => 'Koha::Exceptions::Object',
55         description => 'Invalid data passed',
56         fields      => ['type', 'property', 'value'],
57     },
58 );
59
60 sub full_message {
61     my $self = shift;
62
63     my $msg = $self->message;
64
65     unless ( $msg) {
66         if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
67             $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
68         }
69         elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
70             $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
71         }
72         elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) {
73             $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property );
74         }
75     }
76
77     return $msg;
78 }
79
80 =head1 NAME
81
82 Koha::Exceptions::Object - Base class for Object exceptions
83
84 =head1 Exceptions
85
86 =head2 Koha::Exceptions::Object
87
88 Generic Object exception
89
90 =head2 Koha::Exceptions::Object::DuplicateID
91
92 Exception to be used when a duplicate ID is passed.
93
94 =head2 Koha::Exceptions::Object::FKConstraint
95
96 Exception to be used when a foreign key constraint is broken.
97
98 =head2 Koha::Exceptions::Object::MethodNotFound
99
100 Exception to be used when an invalid class method has been invoked.
101
102 =head2 Koha::Exceptions::Object::PropertyNotFound
103
104 Exception to be used when an invalid object property has been requested.
105
106 =head2 Koha::Exceptions::Object::MethodNotCoveredByTests
107
108 Exception to be used when the invoked method is not covered by tests.
109
110 =head2 Koha::Exceptions::Object::BadValue
111
112 Exception to be used when a bad value has been passed for a property.
113
114 =head1 Class methods
115
116 =head2 full_message
117
118 Overloaded method for exception stringifying.
119
120 =cut
121
122 1;