mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat(sales): add sales feature toggle
This commit is contained in:
@@ -4,24 +4,29 @@ namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SaleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// If the feature toggle is disabled, do not attempt to fetch sales data and return the maintenance view.
|
||||
if (!config('sales.enabled')) {
|
||||
return view('sales.index');
|
||||
}
|
||||
|
||||
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,
|
||||
'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');
|
||||
|
||||
if (! isset($response['champion_sales']) || $response['champion_sales'] === null) {
|
||||
Log::error('LMI has broken');
|
||||
return abort(503, 'Trying to access array offset on value of type null');
|
||||
}
|
||||
|
||||
@@ -29,14 +34,15 @@ class SaleController extends Controller
|
||||
});
|
||||
} catch (\Exception $exception) {
|
||||
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
|
||||
logger()->error('LMI has broken');
|
||||
Log::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' => $exception->getMessage()]);
|
||||
Log::error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]);
|
||||
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
|
||||
}
|
||||
}
|
||||
|
||||
return view('sales.index', ['sales' => $sales]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user