diff --git a/src/Services/Vendors/GeoIp/IpApi.php b/src/Services/Vendors/GeoIp/IpApi.php index 49be84e..a4d044d 100644 --- a/src/Services/Vendors/GeoIp/IpApi.php +++ b/src/Services/Vendors/GeoIp/IpApi.php @@ -26,14 +26,24 @@ public function __construct(array $config = []) public function find(string $ip): mixed { + $response = Http::baseUrl("https://api.ipapi.com/api/") + ->contentType('application/json') + ->acceptJson() + ->get($ip, [ + 'access_key' => $this->token, + 'output' => 'json', + 'language' => 'en' + ]); + + if (!$response->json()) { + throw new \JsonException("Invalid IP API Response."); + } - $response = Http::baseUrl("https://api.ipapi.com/api/")->get($ip, [ - 'access_key' => $this->token, - 'output' => 'json', - 'language' => 'en' - ]); + if (!$response->json('success')) { + throw new \JsonException("IP API Error: " . $response->json('error.info')); + } - return $response->json(); + return $response; } /**