change decode_json() to eval{decode_json()}

This commit is contained in:
Marko Oldenburg 2018-02-27 11:25:20 +01:00
parent de1fb414a0
commit dc4a6be940
2 changed files with 25 additions and 9 deletions

View File

@ -46,7 +46,7 @@ use JSON;
use HttpUtils;
my $version = "0.6.1";
my $version = "0.6.2";
my $bridgeapi = "1.5";
@ -477,7 +477,11 @@ sub NUKIBridge_ResponseProcessing($$$) {
return "NUKIBridge ($name) - invalid json detected: $json";
}
$decode_json = decode_json($json);
my $decode_json = eval{decode_json($json)};
if($@){
Log3 $name, 3, "NUKIBridge ($name) - JSON error while request: $@";
return;
}
if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 and $path eq "list" ) {
@ -745,7 +749,11 @@ sub NUKIBridge_CallBlocking($$$) {
}
my $decode_json = decode_json($data);
my $decode_json = eval{decode_json($data)};
if($@){
Log3 $name, 3, "NUKIBridge ($name) - JSON error while request: $@";
return;
}
return undef if( !$decode_json );

View File

@ -33,7 +33,7 @@ use warnings;
use JSON;
my $version = "0.6.1";
my $version = "0.6.2";
@ -414,7 +414,11 @@ sub NUKIDevice_Parse($$) {
#########################################
#### verarbeiten des JSON Strings #######
my $decode_json = decode_json($result);
my $decode_json = eval{decode_json($result)};
if($@){
Log3 $name, 3, "NUKIDevice ($name) - JSON error while request: $@";
return;
}
if( ref($decode_json) ne "HASH" ) {
@ -527,7 +531,11 @@ sub NUKIDevice_CGI() {
return "NUKIDevice ($name) - invalid json detected: $json";
}
my $decode_json = decode_json($json);
my $decode_json = eval{decode_json($json)};
if($@){
Log3 $name, 3, "NUKIDevice ($name) - JSON error while request: $@";
return;
}
if( ref($decode_json) eq "HASH" ) {