Make exception catching for country lookups less tolerant.

This commit is contained in:
flash 2020-05-09 20:28:25 +00:00
parent 7c1a3179b1
commit d8156dca00

View file

@ -3,6 +3,7 @@ namespace Misuzu\Net;
use Exception;
use InvalidArgumentException;
use GeoIp2\Exception\AddressNotFoundException;
final class IPAddress {
public const VERSION_UNKNOWN = 0;
@ -24,9 +25,9 @@ final class IPAddress {
public static function country(string $address, string $fallback = 'XX'): string {
try {
return GeoIP::resolveCountry($address)->country->isoCode ?? $fallback;
} catch(Exception $e) {}
return $fallback;
} catch(AddressNotFoundException $e) {
return $fallback;
}
}
public static function rawWidth(int $version): int {