-fix: error handling

-fix: error handling malformed JSON
This commit is contained in:
2019-07-16 07:21:05 +02:00
parent 430adca511
commit 8f5f50385b

View File

@@ -48,7 +48,7 @@ use SetExtensions;
sub XiaomiSmartHome_updateSingleReading($$);
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
my $version = "1.42";
my $version = "1.43";
my %XiaomiSmartHome_gets = (
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
@@ -132,20 +132,16 @@ sub XiaomiSmartHome_Read($) {
InternalTimer(gettimeofday() + 2, "XiaomiSmartHome_connect", $hash, 0);
return;
}
my $json = eval{$hash->{helper}{JSON}->incr_parse($buf)};
if ($@) {
Log3 $name, 1, "$name: Read> Error malformed JSON > skipping > " . $buf;
return;
}
my $decoded = eval{decode_json($buf)};
if ($@) {
Log3 $name, 1, "$name: Read> Error while request: $@";
Log3 $name, 1, "$name: Read> Error while request: $@ " . $buf;
return;
}
if ( ! $decoded ) {
Log3 $name, 5, "$name: Read> Error no JSON Data " . $buf;
return;
}
my $json = $hash->{helper}{JSON}->incr_parse($buf);
if ($json)
{
Log3 $name, 5, "$name: Read> [PLAIN] " . $buf;