Skip to content

Commit 7fe6a24

Browse files
authored
Fixed issue "The address xxx.xxx.xxx.xxx is not in the database."
1 parent bc298ce commit 7fe6a24

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Model/IpToCountryRepository.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ public function getCountryCode($ip)
5454
}
5555

5656
if (!$this->ipToCountry[$ip]) {
57-
$datFile = realpath(dirname(__FILE__) . '/../data/GeoLite2-Country.mmdb');
58-
$reader = new \GeoIp2\Database\Reader($datFile);
59-
$record = $reader->country($ip);
60-
if ($record && $record->country && $record->country->isoCode) {
61-
$this->ipToCountry[$ip] = $record->country->isoCode;
62-
}
57+
try {
58+
$datFile = realpath(dirname(__FILE__) . '/../data/GeoLite2-Country.mmdb');
59+
$reader = new \GeoIp2\Database\Reader($datFile);
60+
$record = $reader->country($ip);
61+
if ($record && $record->country && $record->country->isoCode) {
62+
$this->ipToCountry[$ip] = $record->country->isoCode;
63+
}
64+
} catch (\Exception $e) {}
6365
}
6466

6567
if (!$this->ipToCountry[$ip]) {

0 commit comments

Comments
 (0)