From ebaf5c1b07a9494b33edd6086756fecb3112fc11 Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Wed, 14 Aug 2013 18:27:26 +0000 Subject: [PATCH] added: some more complex error handling git-svn-id: https://svn.fhem.de/fhem/trunk@3698 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_openweathermap.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fhem/FHEM/98_openweathermap.pm b/fhem/FHEM/98_openweathermap.pm index 1fe8d1650..8ceba626d 100644 --- a/fhem/FHEM/98_openweathermap.pm +++ b/fhem/FHEM/98_openweathermap.pm @@ -310,7 +310,7 @@ OWO_GetStatus($;$){ my $sendString = $urlString."?".$dataString; if(AttrVal($name, "owoDebug",1) == 0){ Log3($name, 3, "owo $name: sending: $dataString"); - $htmlDummy = $ua->get($sendString); + $htmlDummy = $ua->post($sendString); Log3($name, 3, "owo $name: htmlResponse: ".$htmlDummy->status_line); } else { Log3($name, 3, "owo $name: debug: $dataString"); @@ -318,6 +318,7 @@ OWO_GetStatus($;$){ readingsBeginUpdate($hash); readingsBulkUpdate($hash, "_httpResponse_my", $htmlDummy->status_line) if $htmlDummy; + readingsBulkUpdate($hash, "my_response", $htmlDummy->decoded_content) if $htmlDummy; readingsBulkUpdate($hash, "state","active"); if(AttrVal($name, "owoTimestamp", 0) == 1){ readingsBulkUpdate($hash, "my_lastSent", time); @@ -391,6 +392,16 @@ UpdateReadings($$$){ $url .= "&mode=xml" if($xmlMode eq "1"); $url .= "&APPID=".AttrVal($name, "owoApiKey", ""); eval {$response = $ua->get("$url")}; + +# +# error handling for not found stations (error 404 from server) +# + if($response->decoded_content =~ m/error/i){ + CommandDeleteReading(undef, "$name $prefix.*"); + readingsSingleUpdate($hash, "_httpResponse_".substr($prefix,0,1), $response->decoded_content, 1); + return; + } + if(defined($response)){ if(AttrVal($name, "owoDebug", 1) == 1){ Log3($name, 3, "owo $name: response:\n".$response->decoded_content); @@ -403,7 +414,6 @@ UpdateReadings($$$){ CommandDeleteReading(undef, "$name $prefix.*"); readingsSingleUpdate($hash, "_httpResponse_".substr($prefix,0,1), $response->status_line, 1); - if($xmlMode eq "1" && $response->is_success){ Log3($name, 3, "owo $name: decoding XML"); my $xml = new XML::Simple;