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";
@ -476,8 +476,12 @@ sub NUKIBridge_ResponseProcessing($$$) {
Log3 $name, 3, "NUKIBridge ($name) - invalid json detected: $json";
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" ) {
@ -744,8 +748,12 @@ sub NUKIBridge_CallBlocking($$$) {
return "NUKIDevice ($name) - invalid json detected for $url: $data";
}
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" ) {
@ -526,8 +530,12 @@ sub NUKIDevice_CGI() {
Log3 $name, 3, "NUKIDevice ($name) - invalid json detected: $json";
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" ) {