Bug 29857: Provide a generic full_message method for our exceptions

We pass useful information when throwing exceptions, but we don't
display them! We must display all the details we need when the exception
is stringified.

Test plan:

Use the following snippet:
  use Koha::Exceptions::Elasticsearch;
  Koha::Exceptions::Elasticsearch::BadResponse->throw( type => "a good type", details => "and some details" );

Execute it without and with the patch.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-01-12 10:30:59 +01:00 committed by Fridolin Somers
parent 42096deea4
commit 7429f28cfc

View file

@ -9,4 +9,17 @@ use Exception::Class (
}, },
); );
sub full_message {
my $self = shift;
my $msg = $self->description;
my @fields;
my $field_hash = $self->field_hash;
while ( my ( $field, $value ) = each %$field_hash ) {
push @fields, $field . " => " . $value;
}
return
sprintf "Exception '%s' thrown '%s'" . ( @fields ? " with %s" : "" ) . "\n",
ref($self), $msg, ( @fields ? join ', ', @fields : () );
}
1; 1;