Update _process_success_frame:

If it looks like JSON, parse it as JSON. If not assume normal success
message and send it to cb inside a hash on the 'msg' key.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
This commit is contained in:
Pedro Melo
2014-07-20 22:11:46 +01:00
parent d3fe82af45
commit cbc2429862

View File

@@ -289,16 +289,17 @@ sub _process_success_frame {
$self->nop; $self->nop;
} }
else { else {
if ($msg ne 'OK') { my $info = { msg => $msg };
my $info = eval { JSON::XS::decode_json($msg) }; if ($msg =~ m/^\s*[{]/) {
$info = eval { JSON::XS::decode_json($msg) };
unless ($info) { unless ($info) {
$self->_log_error(qq{unexpected/invalid JSON response '$msg'}); $self->_log_error(qq{unexpected/invalid JSON response '$msg'});
return; return;
} }
my $cb = shift @{ $self->{success_cb_queue} || [] };
$cb->($self, $info) if $cb;
} }
my $cb = shift @{ $self->{success_cb_queue} || [] };
$cb->($self, $info) if $cb;
} }
return 'keep_reading_frames'; return 'keep_reading_frames';