Skip to content

Commit e987c76

Browse files
committed
unified exceptions
1 parent 5dc27c0 commit e987c76

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Next run `php artisan config:publish pulkitjalan/geoip` to publish the config fi
4444

4545
## Usage
4646

47-
Supported Drivers: [maxmind](https://www.maxmind.com/) and [ip-api](http://ip-api.com/)
47+
Supported Drivers: [ip-api](http://ip-api.com/) and [maxmind](https://www.maxmind.com/)
4848

4949
The geoip class takes a config array as the first parameter or defaults to using the `ip-api` driver.
5050

@@ -71,6 +71,7 @@ $config = [
7171
'driver' => 'ip-api',
7272
'ip-api' => [
7373
'key' => 'YOUR IP-API KEY',
74+
7475
// optionally set secure (https) connection (default: false)
7576
'secure' => true
7677
],
@@ -235,10 +236,10 @@ Once you have registered the service provider, you can use the command `php arta
235236

236237
## Services
237238

238-
### Maxmind
239+
### IP-API
239240

240-
You can use the free database from maxmind or their web api service. You can download the free database service [here](http://dev.maxmind.com/geoip/geoip2/geolite2/) or enter your `user id` and `license key` in the config.
241+
IP-API is a free (or paid) service that can also be used instead of the database file or the paid maxmind service. They do have some limitations on the free service so please have a look at the [docs](http://ip-api.com/docs/) first.
241242

242-
### IP-API
243+
### Maxmind
243244

244-
IP-API is a free service that can also be used instead of the database file or the paid maxmind service. They do have some limitations so please have a look at the [docs](http://ip-api.com/docs/) first.
245+
You can use the free database from maxmind or their web api service. You can download the free database service [here](http://dev.maxmind.com/geoip/geoip2/geolite2/) or enter your `user id` and `license key` in the config.

src/Drivers/MaxmindDriver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PulkitJalan\GeoIP\Drivers;
44

55
use PulkitJalan\GeoIP\Exceptions\InvalidCredentialsException;
6+
use PulkitJalan\GeoIP\Exceptions\InvalidDatabaseException;
67
use GeoIp2\Exception\AddressNotFoundException;
78
use GeoIp2\WebService\Client;
89
use GeoIp2\Database\Reader;
@@ -104,6 +105,10 @@ protected function createDatabase()
104105
throw new InvalidCredentialsException();
105106
}
106107

107-
return new Reader($database);
108+
try {
109+
return new Reader($database);
110+
} catch (\MaxMind\Db\Reader\InvalidDatabaseException $e) {
111+
throw new InvalidDatabaseException($e->getMessage());
112+
}
108113
}
109114
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace PulkitJalan\GeoIP\Exceptions;
4+
5+
class InvalidDatabaseException extends \Exception
6+
{
7+
}

src/GeoIPUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function updateMaxmindDatabase()
5050
{
5151
$maxmindDatabaseUrl = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
5252

53-
$database = array_get($this->config, 'maxmind.database', '/tmp/GeoLite2-City.mmdb');
53+
$database = array_get($this->config, 'maxmind.database', false);
5454

5555
$file = $this->requester->url($maxmindDatabaseUrl)->get()->getBody();
5656

tests/GeoIPTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testMaxmindInvalidDatabaseException()
6161
],
6262
];
6363

64-
$this->setExpectedException('MaxMind\Db\Reader\InvalidDatabaseException');
64+
$this->setExpectedException('PulkitJalan\GeoIP\Exceptions\InvalidDatabaseException');
6565

6666
$geoip = new \PulkitJalan\GeoIP\GeoIP($config);
6767
}

0 commit comments

Comments
 (0)