mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -07:00
fix(ip-api): Add error handling and logging for freeipapi.com requests (#2006)
This commit is contained in:
parent
8c161ceae0
commit
12ce6e783e
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 (!empty($infoByIP['countryCode'])) {
|
||||
$peerCountry = render_flag($infoByIP['countryCode'], false);
|
||||
} else {
|
||||
$peerCountry = $lang['NOT_AVAILABLE'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2210,19 +2210,26 @@ function infoByIP(string $ipAddress, int $port = 0): array
|
|||
}
|
||||
|
||||
$context = stream_context_create($contextOptions);
|
||||
$response = file_get_contents($bb_cfg['ip2country_settings']['endpoint'] . $ipAddress, context: $context);
|
||||
|
||||
if ($response !== false) {
|
||||
$json = json_decode($response, true);
|
||||
try {
|
||||
$response = file_get_contents($bb_cfg['ip2country_settings']['endpoint'] . $ipAddress, context: $context);
|
||||
|
||||
if (is_array($json) && !empty($json)) {
|
||||
$data = [
|
||||
'ipVersion' => $json['ipVersion'],
|
||||
'countryCode' => $json['countryCode'],
|
||||
'continent' => $json['continent'],
|
||||
'continentCode' => $json['continentCode']
|
||||
];
|
||||
if ($response !== false) {
|
||||
$json = json_decode($response, true);
|
||||
|
||||
if (is_array($json) && !empty($json)) {
|
||||
$data = [
|
||||
'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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue