Bug 25508: Only return renewal outcomes to the controller
[koha.git] / Koha / Exceptions / Patron / Attribute.pm
1 package Koha::Exceptions::Patron::Attribute;
2
3 use Modern::Perl;
4
5 use Exception::Class (
6
7     'Koha::Exceptions::Patron::Attribute' => {
8         description => 'Something went wrong'
9     },
10     'Koha::Exceptions::Patron::Attribute::InvalidType' => {
11         isa         => 'Koha::Exceptions::Patron::Attribute',
12         description => "the passed type is invalid",
13         fields      => [ "type" ]
14     },
15     'Koha::Exceptions::Patron::Attribute::NonRepeatable' => {
16         isa         => 'Koha::Exceptions::Patron::Attribute',
17         description => "repeatable not set for attribute type and tried to add a new attribute for the same code",
18         fields      => [ "attribute" ]
19     },
20     'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint' => {
21         isa         => 'Koha::Exceptions::Patron::Attribute',
22         description => "unique_id set for attribute type and tried to add a new with the same code and value",
23         fields      => [ "attribute" ]
24     }
25 );
26
27 sub full_message {
28     my $self = shift;
29
30     my $msg = $self->message;
31
32     unless ( $msg) {
33         if ( $self->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
34             $msg = sprintf(
35                 "Tried to add more than one non-repeatable attributes. type=%s value=%s",
36                 $self->attribute->code,
37                 $self->attribute->attribute
38             );
39         }
40         elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::UniqueIDConstraint') ) {
41             $msg = sprintf(
42                 "Your action breaks a unique constraint on the attribute. type=%s value=%s",
43                 $self->attribute->code,
44                 $self->attribute->attribute
45             );
46         }
47         elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) {
48             $msg = sprintf(
49                 "Tried to use an invalid attribute type. type=%s",
50                 $self->type
51             );
52         }
53     }
54
55     return $msg;
56 }
57
58 =head1 NAME
59
60 Koha::Exceptions::Patron::Attribute - Base class for patron attribute exceptions
61
62 =head1 Exceptions
63
64 =head2 Koha::Exceptions::Patron::Attribute
65
66 Generic patron attribute exception
67
68 =head2 Koha::Exceptions::Patron::Attribute::NonRepeatable
69
70 Exception to be used trying to add more than one non-repeatable attribute.
71
72 =head2 Koha::Exceptions::Patron::Attribute::UniqueIDConstraint
73
74 Exception to be used when trying to add an attribute that breaks its type unique constraint.
75
76 =head1 Class methods
77
78 =head2 full_message
79
80 Overloaded method for exception stringifying.
81
82 =cut
83
84 1;