Skip to content

Commit a2a257a

Browse files
committed
Return default when location is not found
1 parent 2ed00c8 commit a2a257a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Torann/GeoIP/GeoIP.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use GeoIp2\Database\Reader;
44
use GeoIp2\WebService\Client;
55

6+
use GeoIp2\Exception\AddressNotFoundException;
7+
68
use Illuminate\Config\Repository;
79
use Illuminate\Session\Store as SessionStore;
810

@@ -166,7 +168,14 @@ private function locate_maxmind( $ip )
166168
$maxmind = new Reader(app_path().'/database/maxmind/GeoLite2-City.mmdb');
167169
}
168170

169-
$record = $maxmind->city($ip);
171+
// Attempt to get location
172+
try {
173+
$record = $maxmind->city($ip);
174+
}
175+
catch(AddressNotFoundException $e)
176+
{
177+
return $this->default_location;
178+
}
170179

171180
$location = array(
172181
"ip" => $ip,

0 commit comments

Comments
 (0)