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