mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 18:20:48 +01:00
fix: Handle null response in SaleController index method
- Add try-catch block to handle null response from API - Log errors and return appropriate HTTP responses - Update error message in 503.blade.php to show exception message if available
This commit is contained in:
@@ -9,15 +9,33 @@ class SaleController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
|
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
|
||||||
$lmi_api_key = config('services.lmi.api_key');
|
$lmi_api_key = config('services.lmi.api_key');
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => 'Bearer '.$lmi_api_key,
|
'Authorization' => 'Bearer ' . $lmi_api_key,
|
||||||
])->get('https://lmi.orianna.dev/api/lol-sales');
|
])->get('https://lmi.orianna.dev/api/lol-sales');
|
||||||
|
|
||||||
return $response->json();
|
$response = $response->json();
|
||||||
|
|
||||||
|
if ($response['champion_sales'] === null) {
|
||||||
|
logger()->error('LMI has broken');
|
||||||
|
return abort(503, 'Trying to access array offset on value of type null');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
});
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($e->getMessage() === 'Trying to access array offset on value of type null') {
|
||||||
|
logger()->error('LMI has broken');
|
||||||
|
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
||||||
|
} else {
|
||||||
|
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $e->getMessage()]);
|
||||||
|
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return view('sales.index', ['sales' => $sales]);
|
return view('sales.index', ['sales' => $sales]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="font-bold text-orange-400 text-8xl">503</h1>
|
<h1 class="font-bold text-orange-400 text-8xl">503</h1>
|
||||||
<h2 class="text-3xl font-bold text-white">Unavailable</h2>
|
<h2 class="text-3xl font-bold text-white">Unavailable</h2>
|
||||||
<p class="mb-8 text-stone-300">The page you are looking for is unavailable.</p>
|
<p class="mb-8 text-stone-300">{{ $exception->getMessage() ?? 'The page you are looking for is unavailable or under maintenance.' }}</p>
|
||||||
<a href="/" class="px-4 py-2 mt-4 text-white bg-orange-400 rounded-md hover:bg-orange-500">Go back to the homepage</a>
|
<a href="/" class="px-4 py-2 mt-4 text-white bg-orange-400 rounded-md hover:bg-orange-500">Go back to the homepage</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user