Bug 17499: (follow-up) More explicit exceptions
[koha.git] / Koha / Exceptions / Patron.pm
1 package Koha::Exceptions::Patron;
2
3 use Modern::Perl;
4
5 use Koha::Exception;
6
7 use Exception::Class (
8     'Koha::Exceptions::Patron' => {
9         isa => 'Koha::Exception',
10     },
11     'Koha::Exceptions::Patron::MissingEmailAddress' => {
12         description => "Patron has no email address",
13     },
14     'Koha::Exceptions::Patron::FailedDelete' => {
15         isa         => 'Koha::Exceptions::Patron',
16         description => "Deleting patron failed"
17     },
18     'Koha::Exceptions::Patron::FailedAnonymizing' => {
19         isa         => 'Koha::Exceptions::Patron',
20         description => "Anonymizing patron reading history failed"
21     },
22     'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => {
23         isa         => 'Koha::Exceptions::Patron',
24         description => "Deleting patron failed, AnonymousPatron is not deleteable"
25     },
26     'Koha::Exceptions::Patron::InvalidUserid' => {
27         isa         => 'Koha::Exceptions::Patron',
28         description => 'Field userid is not valid (probably not unique)',
29         fields      => [ 'userid' ],
30     },
31     'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute' => {
32         isa         => 'Koha::Exceptions::Patron',
33         description => "Mandatory extended attribute missing",
34         fields      => ['type']
35     },
36     'Koha::Exceptions::Patron::NotFound' => {
37         isa => 'Koha::Exceptions::Patron',
38         description => "Patron not found"
39     },
40 );
41
42 sub full_message {
43     my $self = shift;
44
45     my $msg = $self->message;
46
47     unless ( $msg) {
48         if ( $self->isa('Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute') ) {
49             $msg = sprintf("Missing mandatory extended attribute (type=%s)", $self->type );
50         }
51     }
52
53     return $msg;
54 }
55
56 =head1 NAME
57
58 Koha::Exceptions::Patron - Base class for patron exceptions
59
60 =head1 Exceptions
61
62 =head2 Koha::Exceptions::Patron
63
64 Generic patron exception.
65
66 =head2 Koha::Exceptions::Patron::FailedDelete
67
68 Deleting patron failed.
69
70 =head2 Koha::Exceptions::Patron::FailedDeleteAnonymousPatron
71
72 Tried to delete the anonymous patron.
73
74 =head2 Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute
75
76 A required mandatory extended attribute is missing.
77
78 =head1 Class methods
79
80 =head2 full_message
81
82 Overloaded method for exception stringifying.
83
84 =cut
85
86 1;