Make exception catching for country lookups less tolerant.
This commit is contained in:
parent
7c1a3179b1
commit
d8156dca00
1 changed files with 4 additions and 3 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue