mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
fix(ip-api): add error handling and logging for freeipapi.com requests
This commit is contained in:
parent
7f4cc9d3b9
commit
53bd6e4e4f
2 changed files with 19 additions and 10 deletions
|
@ -475,6 +475,8 @@ if ($tor_reged && $tor_info) {
|
||||||
if ($infoByIP = infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])) {
|
if ($infoByIP = infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])) {
|
||||||
if (!empty($infoByIP['countryCode'])) {
|
if (!empty($infoByIP['countryCode'])) {
|
||||||
$peerCountry = render_flag($infoByIP['countryCode'], false);
|
$peerCountry = render_flag($infoByIP['countryCode'], false);
|
||||||
|
} else {
|
||||||
|
$peerCountry = $lang['NOT_AVAILABLE'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2196,19 +2196,26 @@ function infoByIP(string $ipAddress, int $port = 0): array
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = stream_context_create($contextOptions);
|
$context = stream_context_create($contextOptions);
|
||||||
$response = file_get_contents(config()->get('ip2country_settings.endpoint') . $ipAddress, context: $context);
|
|
||||||
|
|
||||||
if ($response !== false) {
|
try {
|
||||||
$json = json_decode($response, true);
|
$response = file_get_contents(config()->get('ip2country_settings.endpoint') . $ipAddress, context: $context);
|
||||||
|
|
||||||
if (is_array($json) && !empty($json)) {
|
if ($response !== false) {
|
||||||
$data = [
|
$json = json_decode($response, true);
|
||||||
'ipVersion' => $json['ipVersion'],
|
|
||||||
'countryCode' => $json['countryCode'],
|
if (is_array($json) && !empty($json)) {
|
||||||
'continent' => $json['continent'],
|
$data = [
|
||||||
'continentCode' => $json['continentCode']
|
'ipVersion' => $json['ipVersion'],
|
||||||
];
|
'countryCode' => $json['countryCode'],
|
||||||
|
'continent' => $json['continent'],
|
||||||
|
'continentCode' => $json['continentCode']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bb_log("[FreeIPAPI] Failed to get IP info for: $ipAddress");
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
bb_log("[FreeIPAPI] " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue