Hide the call to error_cb in a new method _log_error, API changes:
The new error_cb will still receive the same two first parameters, the connection object and the raw error, but will also receive a third parameter, more user friendly error message. Signed-off-by: Pedro Melo <melo@simplicidade.org>
This commit is contained in:
1 parent
bfa5a905d7
commit
522f4e1670
1 file changed
+11
-4
@@ -59,8 +59,6 @@ sub connect {
|
|||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return if $self->{handle};
|
return if $self->{handle};
|
||||||
|
|
||||||
my $err_cb = $self->{error_cb};
|
|
||||||
|
|
||||||
$self->{handle} = AnyEvent::Handle->new(
|
$self->{handle} = AnyEvent::Handle->new(
|
||||||
connect => [$self->{host}, $self->{port}],
|
connect => [$self->{host}, $self->{port}],
|
||||||
|
|
||||||
@@ -69,11 +67,11 @@ sub connect {
|
|||||||
|
|
||||||
on_connect_error => sub {
|
on_connect_error => sub {
|
||||||
$self->_disconnected;
|
$self->_disconnected;
|
||||||
$err_cb->($self, '(connect) ' . ($_[1] || $!));
|
$self->_log_error('(connect failed) ' . ($_[1] || $!));
|
||||||
},
|
},
|
||||||
on_error => sub {
|
on_error => sub {
|
||||||
$self->_disconnected;
|
$self->_disconnected;
|
||||||
$err_cb->($self, '(read) ' . ($_[2] || $!));
|
$self->_log_error('(read error) ' . ($_[2] || $!));
|
||||||
},
|
},
|
||||||
on_eof => sub {
|
on_eof => sub {
|
||||||
$self->_disconnected;
|
$self->_disconnected;
|
||||||
@@ -311,4 +309,13 @@ sub _on_success_frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Error logging
|
||||||
|
sub _log_error {
|
||||||
|
my ($self, $err) = @_;
|
||||||
|
|
||||||
|
$self->{error_cb}->($err, qq{FATAL: dropping connection to host '$self->{host}' port $self->{port}, reason: $err});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
Reference in new issue
Block a user