diff --git a/app/Http/Controllers/SaleController.php b/app/Http/Controllers/SaleController.php index 8afc759..20fcfba 100644 --- a/app/Http/Controllers/SaleController.php +++ b/app/Http/Controllers/SaleController.php @@ -9,15 +9,33 @@ class SaleController extends Controller { public function index() { - $sales = Cache::remember('sales_data', 60 * 60 * 8, static function () { - $lmi_api_key = config('services.lmi.api_key'); + try { + $sales = Cache::remember('sales_data', 60 * 60 * 8, static function () { + $lmi_api_key = config('services.lmi.api_key'); - $response = Http::withHeaders([ - 'Authorization' => 'Bearer '.$lmi_api_key, - ])->get('https://lmi.orianna.dev/api/lol-sales'); + $response = Http::withHeaders([ + 'Authorization' => 'Bearer ' . $lmi_api_key, + ])->get('https://lmi.orianna.dev/api/lol-sales'); + + $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 $response->json(); - }); return view('sales.index', ['sales' => $sales]); } diff --git a/resources/views/errors/503.blade.php b/resources/views/errors/503.blade.php index afc3417..200dc31 100644 --- a/resources/views/errors/503.blade.php +++ b/resources/views/errors/503.blade.php @@ -9,7 +9,7 @@

503

Unavailable

-

The page you are looking for is unavailable.

+

{{ $exception->getMessage() ?? 'The page you are looking for is unavailable or under maintenance.' }}

Go back to the homepage