fix: improve API error handling, add fallback UI, and optimize Nginx connection settings
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user