2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-24 02:59:22 +00:00

26_tahoma.pm:2016-02-20 V 0203 perl exception while parsing json string captured

git-svn-id: https://svn.fhem.de/fhem/trunk@11681 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mike3436 2016-06-17 21:53:44 +00:00
parent 19fb5669fe
commit 10d734deb7

View File

@ -31,6 +31,7 @@
# 2015-08-20 V 0200 communication to server changes from xml to json
# 2015-09-20 V 0201 some standard requests after login which are not neccessary disabled (so the actual requests are not equal to flow of iphone app)
# 2016-01-26 V 0202 bugs forcing some startup warning messages fixed
# 2016-02-20 V 0203 perl exception while parsing json string captured
package main;
@ -46,6 +47,7 @@ use LWP::ConnCache;
use HTTP::Cookies;
sub tahoma_parseGetSetupPlaces($$);
sub tahoma_UserAgent_NonblockingGet($);
my $hash_;
@ -585,8 +587,15 @@ sub tahoma_dispatch($$$)
Log3 $name, 4, "$name: tahoma_dispatch page=$param->{page} dataLen=".length $data;
Log3 $name, (length $data > 120)?4:5, "$name: tahoma_dispatch data=".encode_utf8($data);
#my $json = encode_utf8(decode_json($data));
my $json = JSON->new->utf8(0)->decode($data);
# perl exception while parsing json string captured
my $json = {};
eval { $json = JSON->new->utf8(0)->decode($data); };
if ($@) {
Log3 $name, 3, "$name: tahoma_dispatch json string is faulty";
$hash->{lastError} = 'json string is faulty';
$hash->{logged_in} = 0;
return;
}
if( (ref $json ne 'ARRAY') && ($json->{errorResponse}) ) {
$hash->{lastError} = $json->{errorResponse}{message};
@ -1006,6 +1015,7 @@ sub tahoma_UserAgent_NonblockingGet($)
# keep alive
$agent->conn_cache(LWP::ConnCache->new());
$proxy = '' if (!defined $proxy);
Log3 $name, 4, "tahoma_UserAgent_NonblockingGet create userAgent $userAgent, proxy=$proxy";
}