Better error notification for Geonames plugin

This commit is contained in:
Evan Prodromou 2009-12-23 09:26:43 -08:00
parent 725b2d0475
commit 15b9f61842

View File

@ -86,9 +86,20 @@ class GeonamesPlugin extends Plugin
'lang' => $language,
'type' => 'json')));
if ($result->isOk()) {
if (!$result->isOk()) {
$this->log(LOG_WARNING, "Error code " . $result->code .
" from " . $this->host . " for $name");
return true;
}
$rj = json_decode($result->getBody());
if (count($rj->geonames) > 0) {
if (count($rj->geonames) <= 0) {
$this->log(LOG_WARNING, "No results in response from " .
$this->host . " for $name");
return true;
}
$n = $rj->geonames[0];
$location = new Location();
@ -106,11 +117,6 @@ class GeonamesPlugin extends Plugin
// handled, don't continue processing!
return false;
}
}
// Continue processing; we don't have the answer
return true;
}
/**
* convert an id into a Location object
@ -143,11 +149,21 @@ class GeonamesPlugin extends Plugin
array('geonameId' => $id,
'lang' => $language)));
if ($result->isOk()) {
if (!$result->isOk()) {
$this->log(LOG_WARNING,
"Error code " . $result->code .
" from " . $this->host . " for ID $id");
return false;
}
$rj = json_decode($result->getBody());
if (count($rj->geonames) > 0) {
if (count($rj->geonames) <= 0) {
$this->log(LOG_WARNING,
"No results in response from " .
$this->host . " for ID $id");
return false;
}
$parts = array();
@ -173,8 +189,6 @@ class GeonamesPlugin extends Plugin
$this->setCache(array('id' => $last->geonameId),
$location);
}
}
// We're responsible for this NAMESPACE; nobody else
// can resolve it
@ -217,11 +231,21 @@ class GeonamesPlugin extends Plugin
'lng' => $lon,
'lang' => $language)));
if ($result->isOk()) {
if (!$result->isOk()) {
$this->log(LOG_WARNING,
"Error code " . $result->code .
" from " . $this->host . " for coords $lat, $lon");
return true;
}
$rj = json_decode($result->getBody());
if (count($rj->geonames) > 0) {
if (count($rj->geonames) <= 0) {
$this->log(LOG_WARNING,
"No results in response from " .
$this->host . " for coords $lat, $lon");
return true;
}
$n = $rj->geonames[0];
@ -254,12 +278,6 @@ class GeonamesPlugin extends Plugin
return false;
}
}
// For some reason we don't know, so pass.
return true;
}
/**
* Human-readable name for a location
@ -295,11 +313,21 @@ class GeonamesPlugin extends Plugin
array('geonameId' => $location->location_id,
'lang' => $language)));
if ($result->isOk()) {
if (!$result->isOk()) {
$this->log(LOG_WARNING,
"Error code " . $result->code .
" from " . $this->host . " for ID " . $location->location_id);
return false;
}
$rj = json_decode($result->getBody());
if (count($rj->geonames) > 0) {
if (count($rj->geonames) <= 0) {
$this->log(LOG_WARNING,
"No results " .
" from " . $this->host . " for ID " . $location->location_id);
return false;
}
$parts = array();
@ -320,12 +348,9 @@ class GeonamesPlugin extends Plugin
$this->setCache(array('id' => $location->location_id,
'language' => $language),
$name);
return false;
}
}
}
return true;
return false;
}
/**