You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/lib/NGCP/Panel/Utils/Message.pm

85 lines
2.3 KiB

package NGCP::Panel::Utils::Message;
use Catalyst;
use Sipwise::Base;
method error ($self: Catalyst :$c, Str :$desc, Str :$log?, :$error?) {
# we explicitly declare the invocant to skip the validation for Object
# because we want a class method instead of an object method
if (defined $log) {
$c->log->error($log);
$c->flash(messages => [{type => 'error', text => $desc}]);
return;
}
unless (defined $error) {
$c->log->error("$desc (no detailed information available)");
$c->flash(messages => [{type => 'error', text => "$desc"}]);
return;
}
if (my ($host) = $error =~ /problem connecting to (\S+, port [0-9]+)/ ) {
$c->log->error("$desc ($error)");
$c->flash(messages => [{type => 'error', text => "$desc (A service could not be reached, $host)"}]);
return;
}
if ( ref($error) eq "ARRAY" && @$error >= 2 && $error->[1] eq "showdetails" ) {
$c->log->error("$desc (@$error[0])");
$c->flash(messages => [{type => 'error', text => "$desc (@$error[0])"}]);
return;
}
unless ( $error->isa('DBIx::Class::Exception') ) {
$c->log->error("$desc ($error)");
$c->flash(messages => [{type => 'error', text => $desc}]);
return;
}
if ( my ($dup) = $error =~ /(Duplicate entry \S*)/ ) {
$c->log->error("$desc ($error)");
$c->flash(messages => [{type => 'error', text => "$desc ($dup)"}]);
return;
}
if ( my ($excerpt) = $error =~ /(Column \S+ cannot be null)/ ) {
$c->log->error("$desc ($error)");
$c->flash(messages => [{type => 'error', text => "$desc ($excerpt)"}]);
return;
}
$c->log->error("$desc ($error)");
$c->flash(messages => [{type => 'error', text => $desc}]);
return;
}
__END__
=encoding UTF-8
=head1 NAME
NGCP::Panel::Utils::Message
=head1 DESCRIPTION
Parse messages for log and Web display.
=head1 INTERFACE
=head2 Functions
=head3 C<error>
Params: c (required), desc (required), error, log
Parse Exceptions (mainly DBIx::Class::Exceptions) and show the relevant
bits on the panel. Also log everything to the logger.
=head1 AUTHOR
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.