fix: improve API error handling, add fallback UI, and optimize Nginx connection settings

This commit is contained in:
Ümit Tunç
2026-04-07 15:59:30 +03:00
parent 747043d616
commit 266447e03d
3 changed files with 46 additions and 13 deletions
+19 -6
View File
@@ -128,24 +128,37 @@
</header>
<main class="mt-6">
@php
$response = file_get_contents('https://finance.truncgil.com/api/today.json');
$data = json_decode($response, true);
try {
$response = @file_get_contents('https://finance.truncgil.com/api/today.json');
$data = $response ? json_decode($response, true) : null;
} catch (\Exception $e) {
$data = null;
}
$currencies = ['USD', 'EUR', 'GBP', 'GRA', 'BTC', 'ETH', 'XRP', 'LTC'];
$rates = [];
foreach ($currencies as $currency) {
$rates[$currency] = $data['Rates'][$currency] ?? null;
if (isset($data['Rates'])) {
foreach ($currencies as $currency) {
if (isset($data['Rates'][$currency])) {
$rates[$currency] = $data['Rates'][$currency];
}
}
}
@endphp
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
@foreach($rates AS $currencyName => $rate)
@forelse($rates AS $currencyName => $rate)
<div class="w-full md:w-auto">
@include('currency', [
'currencyName' => $currencyName,
'rate' => $rate
])
</div>
@endforeach
@empty
<div class="col-span-full text-center py-10">
<p class="text-gray-500">Service temporarily unavailable. Please try again later.</p>
</div>
@endforelse
</div>