From c214c33b50ebd6c453973cd05a06ca6fb48f04aa Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Tue, 7 Nov 2017 10:16:32 +0100 Subject: [PATCH] don't pass logger, handler error from caller --- lib/IdPAccountManager/Tools.pm | 11 +++------ lib/IdPAccountManager/WebRequest.pm | 36 ++++++++++++++++------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/IdPAccountManager/Tools.pm b/lib/IdPAccountManager/Tools.pm index b6507fe..6776d9d 100644 --- a/lib/IdPAccountManager/Tools.pm +++ b/lib/IdPAccountManager/Tools.pm @@ -112,11 +112,6 @@ sub mail_notice { my (%args) = @_; my $tt2_file = $args{template}; my $mail_data = $args{data}; - my $logger = $args{logger}; - - $logger->tracef( - sprintf('(template=%s, to=%s)', $args{template}, $args{to}) - ); open SENDMAIL, "|/usr/sbin/sendmail -f $args{from} $args{to}"; @@ -125,9 +120,9 @@ sub mail_notice { FILTERS => { qencode => [ \&qencode, 0 ] }, INCLUDE_PATH => $args{templates_dir} }); - unless ($tt2->process($tt2_file, $mail_data, \*SENDMAIL)) { - $logger->errorf("Error TT2 : %s", $tt2->error()); - } + $tt2->process($tt2_file, $mail_data, \*SENDMAIL) + or die $tt2->error(); + close SENDMAIL; } diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm index 2b107f0..6b97aa3 100755 --- a/lib/IdPAccountManager/WebRequest.pm +++ b/lib/IdPAccountManager/WebRequest.pm @@ -185,14 +185,16 @@ sub respond { ## Mail notification of admins about the error if (@errors_admin) { $self->{out}->{subject} = 'Error notification - web interface'; - IdPAccountManager::Tools::mail_notice( - template => 'mail/notification_generic_error.tt2.eml', - templates_dir => $self->{configuration}->{templates_dir}, - data => $self->{out}, - logger => $self->{logger}, - to => $self->{configuration}->{admin_email}, - from => $self->{configuration}->{notice_from} - ); + eval { + IdPAccountManager::Tools::mail_notice( + template => 'mail/notification_generic_error.tt2.eml', + templates_dir => $self->{configuration}->{templates_dir}, + data => $self->{out}, + to => $self->{configuration}->{admin_email}, + from => $self->{configuration}->{notice_from} + ); + }; + $self->{logger}->errorf("Error TT2 : %s", $EVAL_ERROR) if $EVAL_ERROR; } } @@ -409,14 +411,16 @@ sub req_generate_token { $self->{out}->{subtitle} = 'Generate an authentication token'; ## Send the challenge email with the token - IdPAccountManager::Tools::mail_notice( - template => 'mail/send_authentication_token.tt2.eml', - templates_dir => $self->{configuration}->{templates_dir}, - from => $self->{configuration}->{notice_from} - to => $self->{in}->{email_address}, - data => $self->{out}, - logger => $self->{logger} - ); + eval { + IdPAccountManager::Tools::mail_notice( + template => 'mail/send_authentication_token.tt2.eml', + templates_dir => $self->{configuration}->{templates_dir}, + from => $self->{configuration}->{notice_from} + to => $self->{in}->{email_address}, + data => $self->{out}, + ); + }; + $self->{logger}->errorf("Error TT2 : %s", $EVAL_ERROR) if $EVAL_ERROR; $self->{logger}->infof( "Token send to %s for sp_entityid=%s;token=%s", -- GitLab