Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1039 from joyent/ether/fix-email-errors
Browse files Browse the repository at this point in the history
also log the exception when email sending fails
  • Loading branch information
karenetheridge authored Oct 7, 2020
2 parents 3d03ac3 + 132a8a7 commit 67d79eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Conch/Plugin/Mail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ sub register ($self, $app, $config) {
}

my $email = compose_message($c, %args);
my $log = $c->log;
my $request_id = length($c->req->url) ? $c->req->request_id : undef;
my $tx = $c->tx; # prevent transaction from being destroyed so rollbar can log the request

Mojo::IOLoop->subprocess(
# called in the context of the child process; returns the email object that was
# sent for delivery
sub ($subprocess) {
local $Conch::Log::REQUEST_ID = $request_id;
$log->info('sending email "'
$c->log->info('sending email "'
.($args{template_file} // substr(0,20,$args{template} // $args{content}).'...')
.'" to '.$email->header('to').' from '.$email->header('from')
);
Expand All @@ -108,6 +108,7 @@ sub register ($self, $app, $config) {
}
catch {
my $exception = $_;
$c->get_logger('exception', bunyan => 1, with_trace => 0)->error($exception);
$c->send_exception_to_rollbar(Mojo::Exception->new($exception));
die $exception->$_can('message') ? $exception->message."\n" : $exception;
};
Expand All @@ -119,7 +120,7 @@ sub register ($self, $app, $config) {
sub ($subprocess, $err, @args) {
local $Conch::Log::REQUEST_ID = $request_id;
if ($err) {
$log->error('sending email errored: '.$err);
$c->log->error('sending email errored: '.$err);
return;
}

Expand All @@ -129,7 +130,7 @@ sub register ($self, $app, $config) {
# (methods not available because the class was never composed in this process)
if ($result->{message}) {
chomp $result->{message};
$log->debug('sent email: '.$result->{message});
$c->log->debug('sent email: '.$result->{message});
}
},
);
Expand Down

0 comments on commit 67d79eb

Please sign in to comment.