From d8156dca006dcb5812d33ca18ffa1635ade99ccb Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 9 May 2020 20:28:25 +0000 Subject: [PATCH] Make exception catching for country lookups less tolerant. --- src/Net/IPAddress.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Net/IPAddress.php b/src/Net/IPAddress.php index bbb039be..a7d758be 100644 --- a/src/Net/IPAddress.php +++ b/src/Net/IPAddress.php @@ -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 {