Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance error handling (fixed) #5

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/Mojo/SMTP/Client.pm
Expand Up @@ -140,12 +140,21 @@ sub send {
push @steps, $self->_make_cmd_steps(0, @_);

# non-blocking
my $delay = $self->{delay} = Mojo::IOLoop::Delay->new(ioloop => $self->_ioloop)->steps(@steps)->catch(sub {
shift->emit(finish => $_[0]);
});
my $delay = $self->{delay} = Mojo::IOLoop::Delay
->new(ioloop => $self->_ioloop)
->steps(@steps)
->catch(sub {
# handle exceptions which were thrown
my ($ioloop, $err) = @_;
unless ($err->isa("Mojo::SMTP::Client::Exception") or $err->isa("Mojo::SMTP::Client::Response")) {
$err = Mojo::SMTP::Client::Response->new('', error => $err)
}
$ioloop->emit(finish => $err);
});
$delay->on(finish => sub {
if ($cb) {
my $r = $_[1];
# handle exceptions which where returned
if ($r->isa('Mojo::SMTP::Client::Exception')) {
$r = Mojo::SMTP::Client::Response->new('', error => $r);
}
Expand Down Expand Up @@ -238,7 +247,7 @@ sub _make_cmd_steps {
sub {
eval { $self->{resp_checker}->(@_); $_[1]->{checked} = 1 };
if (my $e = $@) {
die $e unless $e->error->isa('Mojo::SMTP::Client::Exception::Response');
die $e unless ($e->can('error') and $e->error->isa('Mojo::SMTP::Client::Exception::Response'));
my $delay = shift;

$self->{stream}->start if !$prepend && $mi == $#cmd; # XXX: _read_response may stop stream
Expand Down