Bug 29857: Fix behavior
[koha.git] / Koha / Exception.pm
1 package Koha::Exception;
2
3 use Modern::Perl;
4
5 use Exception::Class (
6     'Koha::Exception' => {
7         description => "Something went wrong!"
8     },
9 );
10
11 sub full_message {
12     my $self = shift;
13
14     # If a message was passed manually, use it
15     return sprintf "Exception '%s' thrown '%s'\n", ref($self), $self->message
16       if $self->message;
17
18     my $field_hash = $self->field_hash;
19
20     my $description = $self->description;
21     my @fields;
22
23     foreach my $key ( sort keys %$field_hash ) {
24         push @fields, $key . " => " . $field_hash->{$key}
25           if defined $field_hash->{$key};
26     }
27
28     return
29       sprintf "Exception '%s' thrown '%s'" . ( @fields ? " with %s" : "" ) . "\n",
30       ref($self), $description, ( @fields ? join ', ', @fields : () );
31 }
32
33 =head1 NAME
34
35 Koha::Exception - Base class for exceptions
36
37 =head1 Exceptions
38
39 =head2 Koha::Exception
40
41 Generic exception.
42
43 =head1 Class methods
44
45 =head2 full_message
46
47 Generic method for exception stringifying.
48
49 =cut
50
51 1;