Open aetiv opened 5 years ago
I think you are correct. Is that how other providers do?
For example GoogleMaps - https://github.com/geocoder-php/Geocoder/blob/80da39e5b4049e00540564fdfe8c2ac94383b86c/src/Provider/GoogleMaps/GoogleMaps.php#L196
method validateResponse() - https://github.com/geocoder-php/Geocoder/blob/80da39e5b4049e00540564fdfe8c2ac94383b86c/src/Provider/GoogleMaps/GoogleMaps.php#L400
Throw FATAL if json incorrect, please see
$json = json_decode($content);
// API error
if (!isset($json)) {
throw InvalidServerResponse::create($url);
}
if ('REQUEST_DENIED' === $json->status && 'The provided API key is invalid.' === $json->error_message) {
throw new InvalidCredentials(sprintf('API key is invalid %s', $url));
}
if ('REQUEST_DENIED' === $json->status) {
throw new InvalidServerResponse(
sprintf('API access denied. Request: %s - Message: %s', $url, $json->error_message)
);
}
// you are over your quota
if ('OVER_QUERY_LIMIT' === $json->status) {
throw new QuotaExceeded(sprintf('Daily quota exceeded %s', $url));
}
return empty AddressCollection()
// no result
if (!isset($json->results) || !count($json->results) || 'OK' !== $json->status) {
return new AddressCollection([]);
}
Ok, all providers return empty collection when result is empty, but in combination with cache, this empty collection save to cache and next providers return empty collection from cache.
Maybe no need to save in cache empty collection, but this is incorrect if we use only one provider without Chain and with cache. This you need decide how to solve this problem, but now \Geocoder\Provider\Chain\Chain::geocodeQuery with cache incorrect works( sorry for my English )
@aetiv
Ok, all providers return empty collection when result is empty, but in combination with cache, this empty collection save to cache and next providers return empty collection from cache.
Maybe no need to save in cache empty collection, but this is incorrect if we use only one provider without Chain and with cache. This you need decide how to solve this problem, but now \Geocoder\Provider\Chain\Chain::geocodeQuery with cache incorrect works( sorry for my English )
Sorry, I'm a bit confused what you mean here.
When using the chain provider and the first provider (geoip2) returns an empty result, it will proceed to the next one due to the if (!$result->isEmpty())
check.
If all of the providers return an empty result, this will be cached. There is some discussion relating to this in https://github.com/geocoder-php/Geocoder/issues/904
GeoIp2 return empty collection and save it in cache after that next providers(custom) load from cache empty collection instead of using his code
$result = json_decode(''); //NULL
I think there should not be return '';, but there should be fatal
\Geocoder\Provider\Chain\Chain::geocodeQuery now always return empty collectioon \Geocoder\Model\AddressCollection();